我有问题。我希望收到一条消息,如果成员具有特定角色,并且我希望收到一条消息,如果成员没有所需的角色之一。
我尝试过:
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
答案 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