Razzer
Razzer

Reputation: 884

If Else Statement for discord.py member roles

I have a problem. I want a message that comes and if a member has specific roles and I want a message, that comes if a member has not one of the required roles.

I tried this:

if "676068685546258443" in [y.id for y in message.author.roles] or "721848191829409843" in [y.id for y in message.author.roles] or "768098873772081192" in [y.id for y in message.author.roles]:
      await message.author.send('success')
      return
else:
      user = message.author.mention
      server2error = await message.channel.send(f'you dont have a specific role!')
                
      await server2error.delete()
      return

Upvotes: 1

Views: 223

Answers (1)

Nurqm
Nurqm

Reputation: 4743

discord.Role.id returns integer but you're trying to compare with a string. Also, I'm not sure if message.content == '#2' or '2' == message.content: will work.

You're deleting the server2error just after you send it, it doesn't make any sense. You can delete it with delete_after parameter after a few seconds.

if message.content in ['2', '#2']:
   author_role_ids = [y.id for y in message.author.roles]
   ids = [676068685546258443, 721848191829409843, 768098873772081192]
   check = [True for id in ids if id in author_role_ids]
   if check:
      await message.author.send('success')
   else:
      await message.channel.send(f'{message.author.mention}, you don\'t have a specific role!', delete_after=10)# You can change the time

Upvotes: 2

Related Questions