Someone
Someone

Reputation: 84

Discord.py disabling command in channel

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

Answers (2)

RiveN
RiveN

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')

Python return

Upvotes: 2

FLAK-ZOSO
FLAK-ZOSO

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

Related Questions