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
returns 整数,但您正在尝试与字符串进行比较。另外,我不确定 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
我有问题。我想要一条消息,如果成员具有特定角色,我想要一条消息,如果成员没有所需的角色之一。
我试过这个:
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
returns 整数,但您正在尝试与字符串进行比较。另外,我不确定 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