diff --git a/.env.example b/.env.example index 9d242c9..c216ab6 100644 --- a/.env.example +++ b/.env.example @@ -2,4 +2,5 @@ DISCORD_TOKEN= GUILD_ID= DISCORD_CLIENT_ID= DATABASE_URI= -MOD_CHANNEL_ID= \ No newline at end of file +MOD_CHANNEL_ID= +MOD_ROLE_ID= \ No newline at end of file diff --git a/src/commands/announce.ts b/src/commands/announce.ts index 133ba56..f8cd849 100644 --- a/src/commands/announce.ts +++ b/src/commands/announce.ts @@ -6,7 +6,6 @@ import { SlashCommandChannelOption, TextInputBuilder, TextInputStyle, - PermissionFlagsBits, } from "discord.js"; import { Command } from "../interface"; @@ -15,7 +14,6 @@ export default { .setName("announce") .setDescription("announcement the world something") .setDMPermission(false) - .setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages) .addChannelOption((option: SlashCommandChannelOption) => { return option .setName("channel") diff --git a/src/commands/echo.ts b/src/commands/echo.ts index 22b02a3..def8d5b 100644 --- a/src/commands/echo.ts +++ b/src/commands/echo.ts @@ -6,7 +6,6 @@ import { SlashCommandChannelOption, TextInputBuilder, TextInputStyle, - PermissionFlagsBits, } from "discord.js"; import { Command } from "../interface"; @@ -15,7 +14,6 @@ export default { .setName("echo") .setDescription("Announce a message to a channel") .setDMPermission(false) - .setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages) .addChannelOption((option: SlashCommandChannelOption) => { return option .setName("channel") diff --git a/src/commands/images.ts b/src/commands/images.ts index b0d7004..5c2c1a9 100644 --- a/src/commands/images.ts +++ b/src/commands/images.ts @@ -6,7 +6,6 @@ import { SlashCommandChannelOption, TextInputBuilder, TextInputStyle, - PermissionFlagsBits, } from "discord.js"; import { Command } from "../interface"; @@ -15,7 +14,6 @@ export default { .setName("images") .setDescription("send images") .setDMPermission(false) - .setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages) .addChannelOption((option: SlashCommandChannelOption) => { return option .setName("channel") diff --git a/src/commands/template.ts b/src/commands/template.ts index 4ce01e0..d6e6cb3 100644 --- a/src/commands/template.ts +++ b/src/commands/template.ts @@ -7,7 +7,6 @@ import { StringSelectMenuBuilder, SlashCommandSubcommandBuilder, ChannelType, - PermissionFlagsBits, } from "discord.js"; import { Command } from "../interface"; import db from "../utils/database"; @@ -17,7 +16,6 @@ export default { .setName("template") .setDescription("provides us with the templates") .setDMPermission(false) - .setDefaultMemberPermissions(PermissionFlagsBits.Administrator) .addSubcommand((subcommand: SlashCommandSubcommandBuilder) => subcommand.setName("create").setDescription("Creates Templates"), ) diff --git a/src/config/index.ts b/src/config/index.ts index 13c4509..16495e7 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -10,6 +10,7 @@ const envSchema = z.object({ NODE_ENV: z.string().optional().default("development"), DATABASE_URI: z.string(), MOD_CHANNEL_ID: z.string(), + MOD_ROLE_ID: z.string(), }); const env = envSchema.parse(process.env); @@ -22,4 +23,5 @@ export default { NODE_ENV: env.NODE_ENV, DB_URI: env.DATABASE_URI, MOD_CHANNEL_ID: env.MOD_CHANNEL_ID, + MOD_ROLE_ID: env.MOD_ROLE_ID, }; diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts index 781def3..4ee190d 100644 --- a/src/events/interactionCreate.ts +++ b/src/events/interactionCreate.ts @@ -1,4 +1,4 @@ -import { Collection, Events, Interaction } from "discord.js"; +import { Collection, Events, GuildMemberRoleManager, Interaction } from "discord.js"; import { Command } from "../interface"; import env from "../config/index"; @@ -18,6 +18,7 @@ export default { const interactionChannelId = interaction.channelId; const envChannelId = env.MOD_CHANNEL_ID; + const modRoleId = env.MOD_ROLE_ID; if (command.isMod && interactionChannelId !== envChannelId) { await interaction.reply({ content: "This command can only be executed in a specific channel.", @@ -26,6 +27,14 @@ export default { return; } + if (command.isMod && !(interaction.member?.roles as GuildMemberRoleManager).resolve(modRoleId)) { + await interaction.reply({ + content: "You do not have the required permissions to execute this command.", + ephemeral: true, + }); + return; + } + try { command.execute(interaction); } catch (err) {