Home > front end >  While I try to add second id to channel.id the command does not send on it
While I try to add second id to channel.id the command does not send on it

Time:01-05

Just like in the title. While I add a second id to channel.id the command doesn't send it.

@client.command()
async def test(ctx):
  if ctx.channel.id == 1234567890:
    await ctx.send('testing')

  else:
    await ctx.send('wrong channel')

And now when I try to add another id to:

  if ctx.channel.id == 1234567890, 0987654321:

It does not work.

I tried adding [] and "" to ids but it doesn't work.

CodePudding user response:

You could use a list and the in operator to check for multiple channel IDs.

if ctx.channel.id in [1234567890, 0987654321]:
    await ctx.send('testing')

This is equivalent to:

if ctx.channel.id == 1234567890 or ctx.channel.id == 0987654321:
    await ctx.send('testing')

But the former is more concise and a bit cleaner. It's also more easily expandable.

If you need to add more channel IDs then:

if ctx.channel.id in [1234567890, 0987654321, 1212121, 12121212, etc]:
    await ctx.send('testing')



# alternatively, to keep the line length down
valid_channels = [
    1234567890,
    0987654321,
    1212121,
    12121212,
    etc,
]

if ctx.channel.id in valid_channels:
    await ctx.send('testing')
  • Related