如果其他声明为discord.py成员角色

时间:2020-10-29 21:12:07

标签: python python-3.x discord.py discord.py-rewrite

我有问题。我希望收到一条消息,如果成员具有特定角色,并且我希望收到一条消息,如果成员没有所需的角色之一。

我尝试过:

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

1 个答案:

答案 0 :(得分:2)

discord.Role.id返回整数,但是您正在尝试与字符串进行比较。另外,我不确定if message.content == '#2' or '2' == message.content:是否可以使用。

发送server2error后立即删除它,这没有任何意义。几秒钟后,您可以使用delete_after参数将其删除。

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