2tmb
2tmb

Reputation: 95

How can I restrict a bot to responding in certain channels with discord.py?

I am making a bot that is using cogs and has a couple different commands. I want this bot to only reply in one of the two bot commands channels of the server I’m using it on. I have seen that i can use ctx.channel.id = whatever the Id is, but i would prefer the bot to not be able to respond in the channel at all, including to .help commands. I have seen people do this with on_message, but I’m not sure how I would do that with cogs. Any help would be much appreciated. My intended result is basically to have the bot only respond in two channels, the two bot channels that i specify, to any commands including the .help command. Thanks!

Upvotes: 0

Views: 4497

Answers (2)

PRA7H1K
PRA7H1K

Reputation: 117

As @Lu M said, the easiest way to do this would be to disable permissions for your bot. But if you want to do this in your code, you can use if statements to check what the channel ID is.

if ctx.channel.id == <channel_id_here>:
   return 
   # if this if statement returns True, this will stop the command from doing 
   further actions.

else:
   # do stuff here

Upvotes: 1

chluebi
chluebi

Reputation: 1829

The easiest way to do this is not actually via code but via permissions on the server. On your server you should find a role with the same name as your bot, whose permissions (including send messages) you can change for seperate channels.

Upvotes: 1

Related Questions