In a discord server, how can I prevent admin users to use a slash command in EVERY channel?

127 views Asked by At

To start with, I'm new to discord bot development. I've created and deployed a bot with a slash command and added the bot in a server, where I'm an admin myself. I have already set the bot and its slash command, under Sever Setting/Integration, to be used in a test channel only for everyone. Things works as I expected for non-admin users. They can use the slash command only in the test channel I specified in Integration. However, I noticed that admin users have access to the slash command in ANY channels. Is there a way to prevent that? Limiting admin users to use the command only in the specified test channel only?

I've try to override the command permission in Integration for the command itself to specify the test channel. But nothing's changed. Admins still have access to the command and every channels in the server.

2

There are 2 answers

0
RogueMan On

Sadly it's not possible to "hide" the slashcommands for admin users as the admin privilege overrides these settings. The only way you can achieve something like this is by pre-defining every blacklisted channel within your code and not executing the commands. You could just delete the interaction response or however you would like to handle this.

1
Mey On

I don't think it's possible to limit the channel they can invoke the command in. However, you could manually hard code it in your command handler function for it to return if it's not used in the correct channel.

You could do something like:

let channelIds = []; // Add your allowed channels here

if (!channelIds.includes(interaction.channelId)) {
    return await interaction.reply("Incorrect channel");
}