Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Discord.py disabling command in channel

so I wanted to disable command in one channel.
This is my code:

@bot.command()
async def test(ctx):
  if ctx.message.channel.id != '923252963105976341':
    await ctx.send('Test')
  elif ctx.message.channel.id == '923252963105976341':
    pass

The problem is that this command is still working.
Can someone help?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading