Reputation: 410
I want the users with my bot to be able to configure the bot to only run in certain channels. I was able to achieve this when I was using the on_message
function by checking which channel the message was coming from. Now I'm using Cogs and I'm not sure how I would approach this problem.
My Old Code was something like this:
val_channels = ['a', 'b', 'c']
if message.channel in val_channels:
# Do Something
else:
print('The bot was configured to: ' + ', '.join(val_channels))
Upvotes: 0
Views: 1795
Reputation: 86
You can verify if the ctx.message.channel.id
matches with your list.
class Greetings(commands.Cog):
@commands.command()
async def hello(self, ctx):
"""Says hello"""
if ctx.message.channel.id in val_channels:
await ctx.send('Hello!')
else:
await ctx.send('You can not use this command here.')
But if you still want to use a on_message
event inside a cog, you will need do modify the decorator. Link to doc
class Greetings(commands.Cog):
@commands.Cog.listener()
async def on_message(self, message):
if message.channel.id in val_channels:
# Do something
else:
print('The bot was configured to: ' + ', '.join(val_channels))
Upvotes: 1