Skip to content

Commit f0e20cc

Browse files
authored
✨ tweak: add permission checks
1 parent 27dcd54 commit f0e20cc

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/commands/support/support.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { SlashCommandBuilder, ModalBuilder, ActionRowBuilder, TextInputBuilder, TextInputStyle } = require('discord.js');
1+
const { SlashCommandBuilder, ModalBuilder, ActionRowBuilder, TextInputBuilder, TextInputStyle, PermissionFlagsBits } = require('discord.js');
22

33
module.exports = {
44
data: new SlashCommandBuilder()
@@ -12,6 +12,24 @@ module.exports = {
1212
return;
1313
}
1414

15+
// Check if bot has necessary permissions to create threads in this channel
16+
const botMember = interaction.guild.members.me;
17+
const requiredPermissions = [
18+
PermissionFlagsBits.ManageThreads,
19+
PermissionFlagsBits.CreatePrivateThreads,
20+
PermissionFlagsBits.SendMessages,
21+
PermissionFlagsBits.SendMessagesInThreads,
22+
PermissionFlagsBits.ViewChannel
23+
];
24+
25+
if (!botMember.permissionsIn(interaction.channel).has(requiredPermissions)) {
26+
await interaction.reply({
27+
content: 'I don\'t have the necessary permissions to create support tickets in this channel. Please use this command in an authorized channel or contact an administrator.',
28+
ephemeral: true
29+
});
30+
return;
31+
}
32+
1533
// Create modal
1634
const modal = new ModalBuilder()
1735
.setCustomId('supportModal')

0 commit comments

Comments
 (0)