How to Restrict A Discord Bot to One Channel, A Step-by-Step Guide
In 2021, Discord introducted a new feature called slash commands. Before that commands were text based in public channels using a prefix (aka a word or symbol before the actual command. Many bots, for example mee6, used !help as a prefix, which made it difficult for users when multiple bots used the same prefix). With slash commands, you can now use commands in any channel, even in DMs. This is great for bot developers, but not so great for server owners and discord mods.
Before the introduction of slash commands, restricting the text commands to a specific channel required denying the 'View Channel' permission to bots across all channels except the intended one. Slash commands are not affected by this permission, so you can't restrict a bot to one channel by denying the 'View Channel' permission anymore.
To limit a bot to a singular channel, follow the steps below:
- Navigate to the 'Integrations' tab in your server settings
Firstly, click the icon of your server located on the left side of the screen.Next, hover over ‘Server Settings,’ and choose ‘Integrations’ from the opened menu.
- Click 'Manage' next to the bot you want to restrict
Go to the 'Integrations' page and find 'Bots and Apps'. This is where you can view all the available bots on your server. To limit the use of commands in specific channels, you must manage each bot individually. Start by clicking on 'Manage' beside the first bot.
- Change slash commands permissions
In the settings, you can change which members or roles are able to use commands, and also which channels allow commands. To limit the bot to one channel, select ‘Add Channels’ next to the ‘Channels’ menu. Then, select the channel you want to allow commands in. You can also select multiple channels if you want to allow commands in more than one channel.
- Deny the 'Use Slash Commands' permission for all channels
Next, you must deny the 'Use Slash Commands' permission for all channels. To do this, deny the slash command permission for All Channels. This will prevent your users from using commands in all channels exept the ones you select in the previous step. Now, users won’t be able to use slash commands in any other channel with the X selected.
- Use toggles to change which channels allow commands
If you want to change which members or roles can use bot commands, you can do so by clicking on 'Add Roles & Members' in the 'Roles & Members' menu. The process is exactly the same.
There's also a command-specific list where you can set custom permissions for each command. By default, these are all synced to the command permission at the top. However, you can unsync an individual command to make further customisations.
- Verify that your changes have taken effect
To verify that your changes have taken effect, go to the channel you selected in step 3 as a non-admin user. If you dont have an alternative account to test with, you can also view the server as a non-admin user To do this, go to 'Server Settings' and then 'Roles'. Finally, select a non-admin role, scroll down and click on 'View Server As Role'. If you can't use slash commands in the channel, you have successfully restricted the bot to one channel.
As you can see, the user is unable to use slash commands in the channel and only has built-in commands available.
In the image above, you can see the same user in a channel where slash commands are allowed. The user can now use slash commands in this channel and we verified that they are indeed available to non-admin users.
If you followed these steps correctly, your users will only be able to use slash commands in the channels you selected. If you want to allow a bot to use slash commands in all channels again, simply toggle 'All Channels' again.
Thats it for this guide. Make sure you check out how you can increase the server activity to make it more fun and engaged.