Reputation: 84
I'm trying to disable the command in one channel, but the command is still working.
@bot.command()
async def test(ctx):
if ctx.message.channel.id != '923252963105976341':
await ctx.send('Test')
elif ctx.message.channel.id == '923252963105976341':
pass
Upvotes: 0
Views: 427
Reputation: 2663
It's happening because you pasted channel id as a string
instead of an int
. You might also want to use return
instead of creating an elif
statement. It might mess with your code if you create more advanced commands.
@bot.command()
async def test(ctx):
if ctx.message.channel.id == 923252963105976341:
return # it will stop executing your command
await ctx.send('Test')
Upvotes: 2
Reputation: 4137
In discord.py
the channel.id
attribute is always int
type.
>>> ctx.channel.id
852838885389762581 #Possible output
>>> ctx.channel.id
'852838885389762581' #Impossible output
In your case you only have to change you code to this:
@bot.command()
async def test(ctx):
if ctx.message.channel.id != 923252963105976341:
await ctx.send('Test')
You can remove the last two lines, since they're completely useless.
Notice than not(id != x) => id == x
.
Upvotes: 1