繁体   English   中英

针对 discord.py 成员角色的 If Else 语句

[英]If Else Statement for discord.py member roles

我有个问题。 我想要一条消息,如果成员具有特定角色,我想要一条消息,如果成员没有所需的角色之一。

我试过这个:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM