Skip to content

Commit

Permalink
⚡️ Change of permission check position
Browse files Browse the repository at this point in the history
  • Loading branch information
MotiCAT committed Jan 2, 2024
1 parent a0cd1ea commit c872bc9
Show file tree
Hide file tree
Showing 20 changed files with 69 additions and 66 deletions.
73 changes: 57 additions & 16 deletions src/deploy-commands.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { REST, Routes, SlashCommandBuilder } from 'discord.js';
import { PermissionsBitField, REST, Routes, SlashCommandBuilder } from 'discord.js';
import { config } from 'dotenv';

config();
Expand All @@ -9,7 +9,8 @@ const commands = [
.setName('addrole')
.setDescription('ロールを付与します')
.addRoleOption((option) => option.setName('role').setDescription('付与するロール').setRequired(true))
.addUserOption((option) => option.setName('member').setDescription('ロールを付与するメンバー').setRequired(true)),
.addUserOption((option) => option.setName('member').setDescription('ロールを付与するメンバー').setRequired(true))
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageRoles),
new SlashCommandBuilder()
.setName('avatar')
.setDescription('ユーザーのアバターを表示します')
Expand All @@ -29,24 +30,37 @@ const commands = [
.addUserOption((option) =>
option.setName('member').setDescription('メッセージを削除するメンバー').setRequired(true)
)
.addIntegerOption((option) => option.setName('amount').setDescription('削除するメッセージの数').setRequired(true)),
new SlashCommandBuilder().setName('deletejoin').setDescription('入室メッセージを削除します'),
new SlashCommandBuilder().setName('deleteleave').setDescription('退室メッセージを削除します'),
.addIntegerOption((option) => option.setName('amount').setDescription('削除するメッセージの数').setRequired(true))
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageMessages),
new SlashCommandBuilder()
.setName('deletejoin')
.setDescription('入室メッセージを削除します')
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator),
new SlashCommandBuilder()
.setName('deleteleave')
.setDescription('退室メッセージを削除します')
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator),
new SlashCommandBuilder().setName('help').setDescription('ヘルプを表示します'),
new SlashCommandBuilder().setName('inlist').setDescription('管理者限定コマンド'),
new SlashCommandBuilder().setName('invite').setDescription('サーバーのの招待リンクを表示します'),
new SlashCommandBuilder()
.setName('invite')
.setDescription('サーバーのの招待リンクを表示します')
.setDefaultMemberPermissions(PermissionsBitField.Flags.CreateInstantInvite),
new SlashCommandBuilder()
.setName('joinmsg')
.setDescription('入室メッセージを設定します')
.addStringOption((option) => option.setName('detail').setDescription('入室メッセージ').setRequired(true)),
.addStringOption((option) => option.setName('detail').setDescription('入室メッセージ').setRequired(true))
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator),
new SlashCommandBuilder()
.setName('kick')
.setDescription('ユーザーをキックします')
.addUserOption((option) => option.setName('member').setDescription('キックするユーザー').setRequired(true)),
.addUserOption((option) => option.setName('member').setDescription('キックするユーザー').setRequired(true))
.setDefaultMemberPermissions(PermissionsBitField.Flags.KickMembers),
new SlashCommandBuilder()
.setName('leavemsg')
.setDescription('退室メッセージを設定します')
.addStringOption((option) => option.setName('detail').setDescription('退室メッセージ').setRequired(true)),
.addStringOption((option) => option.setName('detail').setDescription('退室メッセージ').setRequired(true))
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator),
new SlashCommandBuilder()
.setName('mcskin')
.setDescription('Minecraftのスキンを表示します')
Expand All @@ -56,16 +70,41 @@ const commands = [
.setDescription('Minecraftサーバーのステータスを表示します')
.addStringOption((option) => option.setName('address').setDescription('サーバーアドレス').setRequired(true))
.addIntegerOption((option) => option.setName('port').setDescription('ポート番号').setRequired(false)),
new SlashCommandBuilder().setName('memberlog').setDescription('メンバーログを設定します'),
new SlashCommandBuilder().setName('memberlogstop').setDescription('メンバーログを停止します'),
new SlashCommandBuilder().setName('msglog').setDescription('メッセージログを設定します'),
new SlashCommandBuilder().setName('msglogstop').setDescription('メッセージログを停止します'),
new SlashCommandBuilder()
.setName('memberlog')
.setDescription('メンバーログを設定します')
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageChannels),
new SlashCommandBuilder()
.setName('memberlogstop')
.setDescription('メンバーログを停止します')
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageChannels),
new SlashCommandBuilder()
.setName('msglog')
.setDescription('メッセージログを設定します')
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageChannels),
new SlashCommandBuilder()
.setName('msglogstop')
.setDescription('メッセージログを停止します')
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageChannels),
new SlashCommandBuilder().setName('ping').setDescription('BotのPingを表示します'),
new SlashCommandBuilder()
.setName('remrole')
.setDescription('ロールを剥奪します')
.addRoleOption((option) => option.setName('role').setDescription('剥奪するロール').setRequired(true))
.addUserOption((option) => option.setName('member').setDescription('ロールを剥奪するメンバー').setRequired(true)),
.addUserOption((option) => option.setName('member').setDescription('ロールを剥奪するメンバー').setRequired(true))
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageRoles),
new SlashCommandBuilder()
.setName('resdelete')
.setDescription('レスポンスを削除します')
.addStringOption((option) => option.setName('keyword').setDescription('削除するレスポンス').setRequired(true))
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageMessages),
new SlashCommandBuilder().setName('resnow').setDescription('レスポンスを表示します'),
new SlashCommandBuilder()
.setName('response')
.setDescription('レスポンスを設定します')
.addStringOption((option) => option.setName('keyword').setDescription('レスポンスのキーワード').setRequired(true))
.addStringOption((option) => option.setName('response').setDescription('レスポンス').setRequired(true))
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageMessages),
new SlashCommandBuilder()
.setName('search')
.setDescription('Googleで検索します')
Expand All @@ -76,13 +115,15 @@ const commands = [
.setName('timeout')
.setDescription('タイムアウトします')
.addUserOption((option) => option.setName('member').setDescription('タイムアウトするメンバー').setRequired(true))
.addIntegerOption((option) => option.setName('time').setDescription('タイムアウトする時間(分)').setRequired(true)),
.addIntegerOption((option) => option.setName('time').setDescription('タイムアウトする時間(分)').setRequired(true))
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers),
new SlashCommandBuilder()
.setName('untimeout')
.setDescription('タイムアウトを解除します')
.addUserOption((option) =>
option.setName('member').setDescription('タイムアウトを解除するメンバー').setRequired(true)
),
)
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers),
new SlashCommandBuilder()
.setName('user')
.setDescription('ユーザーの情報を表示します')
Expand Down
2 changes: 0 additions & 2 deletions src/interactions/addrole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { ChatInputCommandInteraction, GuildMember, PermissionsBitField, Role } f

export async function addroleCommand(interaction: ChatInputCommandInteraction) {
if (!(interaction.member instanceof GuildMember)) return;
if (!interaction.member?.permissions.has(PermissionsBitField.Flags.ManageRoles))
return interaction.reply(embeds.PermissionError);
if (!interaction.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ManageRoles))
return interaction.reply(embeds.roleAddPermissionError);
const role = interaction.options.getRole('role') as Role;
Expand Down
2 changes: 0 additions & 2 deletions src/interactions/ban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { ChatInputCommandInteraction, GuildMember, PermissionsBitField } from 'd

export async function banCommand(interaction: ChatInputCommandInteraction) {
if (!(interaction.member instanceof GuildMember)) return;
if (!interaction.member?.permissions.has(PermissionsBitField.Flags.BanMembers))
return interaction.reply(embeds.PermissionError);
if (!interaction.guild?.members.me?.permissions.has(PermissionsBitField.Flags.BanMembers))
return interaction.reply(embeds.banPermissionError);
const member = interaction.options.getMember('member') as GuildMember;
Expand Down
2 changes: 0 additions & 2 deletions src/interactions/clear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {

export async function clearCommand(interaction: ChatInputCommandInteraction) {
if (!(interaction.member instanceof GuildMember)) return;
if (!interaction.member?.permissions.has(PermissionsBitField.Flags.ManageMessages))
return interaction.reply(embeds.PermissionError);
if (!interaction.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ManageMessages))
return interaction.reply(embeds.clearPermissionError);
const member = interaction.options.getMember('member') as GuildMember;
Expand Down
4 changes: 1 addition & 3 deletions src/interactions/deletejoin.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { ServerJoinData } from '../Utils/ServerData';
import { embeds } from '../embeds';
import { Guild, ChatInputCommandInteraction, PermissionsBitField, GuildMember } from 'discord.js';
import { Guild, ChatInputCommandInteraction, GuildMember } from 'discord.js';
import { writeFile, readFileSync } from 'fs';

export async function deletejoinCommand(interaction: ChatInputCommandInteraction) {
if (!(interaction.member instanceof GuildMember)) return;
if (!interaction.member?.permissions.has(PermissionsBitField.Flags.Administrator))
return interaction.reply(embeds.PermissionError);
const guild = interaction.guild as Guild;
const serverId = guild.id;
const rawData = readFileSync('./database/join_messages.json', 'utf-8');
Expand Down
4 changes: 1 addition & 3 deletions src/interactions/deleteleave.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { ServerLeaveData } from '../Utils/ServerData';
import { embeds } from '../embeds';
import { Guild, ChatInputCommandInteraction, PermissionsBitField, GuildMember } from 'discord.js';
import { Guild, ChatInputCommandInteraction, GuildMember } from 'discord.js';
import { writeFile, readFileSync } from 'fs';

export async function deleteleaveCommand(interaction: ChatInputCommandInteraction) {
if (!(interaction.member instanceof GuildMember)) return;
if (!interaction.member?.permissions.has(PermissionsBitField.Flags.Administrator))
return interaction.reply(embeds.PermissionError);
const guild = interaction.guild as Guild;
const serverId = guild.id;
const rawData = readFileSync('./database/leave_messages.json', 'utf-8');
Expand Down
2 changes: 0 additions & 2 deletions src/interactions/invite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {

export async function inviteCommand(interaction: ChatInputCommandInteraction) {
if (!(interaction.member instanceof GuildMember)) return;
if (!interaction.member?.permissions.has(PermissionsBitField.Flags.CreateInstantInvite))
return interaction.reply(embeds.PermissionError);
if (!interaction.guild?.members.me?.permissions.has(PermissionsBitField.Flags.CreateInstantInvite))
return interaction.reply(embeds.invitePermissionError);
const channel = interaction.channel as TextBasedChannel;
Expand Down
4 changes: 1 addition & 3 deletions src/interactions/joinmsg.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { ServerJoinData } from '../Utils/ServerData';
import { embeds } from '../embeds';
import { Guild, ChatInputCommandInteraction, PermissionsBitField, GuildMember, TextBasedChannel } from 'discord.js';
import { Guild, ChatInputCommandInteraction, GuildMember, TextBasedChannel } from 'discord.js';
import { writeFile, readFileSync } from 'fs';

export async function joinmsgCommand(interaction: ChatInputCommandInteraction) {
if (!(interaction.member instanceof GuildMember)) return;
if (!interaction.member?.permissions.has(PermissionsBitField.Flags.Administrator))
return interaction.reply(embeds.PermissionError);
const detail = interaction.options.getString('detail');
const channel = interaction.channel as TextBasedChannel;
const guild = interaction.guild as Guild;
Expand Down
2 changes: 0 additions & 2 deletions src/interactions/kick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { PermissionsBitField, ChatInputCommandInteraction, GuildMember } from 'd

export async function kickCommand(interaction: ChatInputCommandInteraction) {
if (!(interaction.member instanceof GuildMember)) return;
if (!interaction.member?.permissions.has(PermissionsBitField.Flags.KickMembers))
return interaction.reply('コマンドを使用する権限がありません。');
if (!interaction.guild?.members.me?.permissions.has(PermissionsBitField.Flags.KickMembers))
return interaction.reply(embeds.kickPermissionError);
const member = interaction.options.getMember('member') as GuildMember;
Expand Down
4 changes: 1 addition & 3 deletions src/interactions/leavemsg.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { ServerLeaveData } from '../Utils/ServerData';
import { embeds } from '../embeds';
import { Guild, ChatInputCommandInteraction, PermissionsBitField, GuildMember, TextBasedChannel } from 'discord.js';
import { Guild, ChatInputCommandInteraction, GuildMember, TextBasedChannel } from 'discord.js';
import { readFileSync, writeFile } from 'fs';

export async function leavemsgCommand(interaction: ChatInputCommandInteraction) {
if (!(interaction.member instanceof GuildMember)) return;
if (!interaction.member?.permissions.has(PermissionsBitField.Flags.Administrator))
return interaction.reply(embeds.PermissionError);
const detail = interaction.options.getString('detail') as string;
const channel = interaction.channel as TextBasedChannel;
const guild = interaction.guild as Guild;
Expand Down
4 changes: 1 addition & 3 deletions src/interactions/memberlog.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { ServerMemberData } from '../Utils/ServerData';
import { embeds } from '../embeds';
import { Guild, ChatInputCommandInteraction, PermissionsBitField, GuildMember, TextBasedChannel } from 'discord.js';
import { Guild, ChatInputCommandInteraction, GuildMember, TextBasedChannel } from 'discord.js';
import { readFileSync, writeFile } from 'fs';

export async function memberlogCommand(interaction: ChatInputCommandInteraction) {
if (!(interaction.member instanceof GuildMember)) return;
if (!interaction.member?.permissions.has(PermissionsBitField.Flags.ManageChannels))
return interaction.reply(embeds.PermissionError);
const channel = interaction.channel as TextBasedChannel;
const guild = interaction.guild as Guild;
const serverId = guild.id;
Expand Down
4 changes: 1 addition & 3 deletions src/interactions/memberlogstop.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { ServerMemberData } from '../Utils/ServerData';
import { embeds } from '../embeds';
import { Guild, ChatInputCommandInteraction, PermissionsBitField, GuildMember } from 'discord.js';
import { Guild, ChatInputCommandInteraction, GuildMember } from 'discord.js';
import { readFileSync, writeFile } from 'fs';

export async function memberlogstopCommand(interaction: ChatInputCommandInteraction) {
if (!(interaction.member instanceof GuildMember)) return;
if (!interaction.member?.permissions.has(PermissionsBitField.Flags.ManageChannels))
return interaction.reply(embeds.PermissionError);
const guild = interaction.guild as Guild;
const serverId = guild.id;
const rawData = readFileSync('./database/memberlogs.json', 'utf-8');
Expand Down
4 changes: 1 addition & 3 deletions src/interactions/msglog.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { ServerMsgData } from '../Utils/ServerData';
import { embeds } from '../embeds';
import { Guild, ChatInputCommandInteraction, PermissionsBitField, GuildMember, TextBasedChannel } from 'discord.js';
import { Guild, ChatInputCommandInteraction, GuildMember, TextBasedChannel } from 'discord.js';
import { readFileSync, writeFile } from 'fs';

export async function msglogCommand(interaction: ChatInputCommandInteraction) {
if (!(interaction.member instanceof GuildMember)) return;
if (!interaction.member?.permissions.has(PermissionsBitField.Flags.ManageChannels))
return interaction.reply(embeds.PermissionError);
const channel = interaction.channel as TextBasedChannel;
const guild = interaction.guild as Guild;
const serverId = guild.id;
Expand Down
4 changes: 1 addition & 3 deletions src/interactions/msglogstop.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { ServerMsgData } from '../Utils/ServerData';
import { embeds } from '../embeds';
import { Guild, ChatInputCommandInteraction, PermissionsBitField, GuildMember } from 'discord.js';
import { Guild, ChatInputCommandInteraction, GuildMember } from 'discord.js';
import { readFileSync, writeFile } from 'fs';

export async function msglogstopCommand(interaction: ChatInputCommandInteraction) {
if (!(interaction.member instanceof GuildMember)) return;
if (!interaction.member?.permissions.has(PermissionsBitField.Flags.ManageChannels))
return interaction.reply(embeds.PermissionError);
const guild = interaction.guild as Guild;
const serverId = guild.id;
const rawData = readFileSync('./database/msglogs.json', 'utf-8');
Expand Down
4 changes: 1 addition & 3 deletions src/interactions/resdelete.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { ServerResponseData } from '../Utils/ServerData';
import { embeds } from '../embeds';
import { PermissionsBitField, ChatInputCommandInteraction, Guild, GuildMember } from 'discord.js';
import { ChatInputCommandInteraction, Guild, GuildMember } from 'discord.js';
import { writeFile } from 'fs';
import { readFileSync } from 'fs';

export async function resdeleteCommand(interaction: ChatInputCommandInteraction) {
if (!(interaction.member instanceof GuildMember)) return;
if (!interaction.member?.permissions.has(PermissionsBitField.Flags.ManageMessages))
return interaction.reply('貴方にはこのコマンドを使用する権限がありません。');
const keyword = interaction.options.getString('keyword') as string;
const guild = interaction.guild as Guild;
const serverId = guild.id;
Expand Down
4 changes: 1 addition & 3 deletions src/interactions/response.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { ServerResponseData } from '../Utils/ServerData';
import { embeds } from '../embeds';
import { Guild, ChatInputCommandInteraction, PermissionsBitField, GuildMember } from 'discord.js';
import { Guild, ChatInputCommandInteraction, GuildMember } from 'discord.js';
import { readFileSync, writeFile } from 'fs';

export async function responseCommand(interaction: ChatInputCommandInteraction) {
if (!(interaction.member instanceof GuildMember)) return;
if (!interaction.member?.permissions.has(PermissionsBitField.Flags.ManageMessages))
return interaction.reply(embeds.PermissionError);
const keyword = interaction.options.getString('keyword') as string;
const response = interaction.options.getString('response') as string;
const guild = interaction.guild as Guild;
Expand Down
4 changes: 1 addition & 3 deletions src/interactions/rolelog.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { ServerRoleData } from '../Utils/ServerData';
import { embeds } from '../embeds';
import { ChatInputCommandInteraction, PermissionsBitField, Guild, GuildMember, TextBasedChannel } from 'discord.js';
import { ChatInputCommandInteraction, Guild, GuildMember, TextBasedChannel } from 'discord.js';
import { writeFile, readFileSync } from 'fs';

export async function rolelogCommand(interaction: ChatInputCommandInteraction) {
if (!(interaction.member instanceof GuildMember)) return;
if (!interaction.member?.permissions.has(PermissionsBitField.Flags.ManageChannels))
return interaction.reply(embeds.PermissionError);
const channel = interaction.channel as TextBasedChannel;
const guild = interaction.guild as Guild;
const serverId = guild.id;
Expand Down
4 changes: 1 addition & 3 deletions src/interactions/rolelogstop.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { ServerRoleData } from '../Utils/ServerData';
import { embeds } from '../embeds';
import { ChatInputCommandInteraction, PermissionsBitField, Guild, GuildMember } from 'discord.js';
import { ChatInputCommandInteraction, Guild, GuildMember } from 'discord.js';
import { writeFile, readFileSync } from 'fs';

export async function rolelogstopCommand(interaction: ChatInputCommandInteraction) {
if (!(interaction.member instanceof GuildMember)) return;
if (!interaction.member?.permissions.has(PermissionsBitField.Flags.ManageChannels))
return interaction.reply(embeds.PermissionError);
const guild = interaction.guild as Guild;
const serverId = guild.id;
const rawData = readFileSync('/database/rolelogs.json', 'utf-8');
Expand Down
Loading

0 comments on commit c872bc9

Please sign in to comment.