Python 如果作者没有';我没有特定的角色

Python 如果作者没有';我没有特定的角色,python,discord,Python,Discord,基本上和问题一样。我想创建一个bot,如果邮件作者在我的服务器中没有bot或trusted角色,它将删除带有附件的邮件 目前我有: **if message.attachments: if not "*roleID*" or "roleID" in [role.id for role in message.author.roles]: await client.delete_message(message) await client.s

基本上和问题一样。我想创建一个bot,如果邮件作者在我的服务器中没有bot或trusted角色,它将删除带有附件的邮件

目前我有:

 **if message.attachments:
       if not "*roleID*" or "roleID" in [role.id for role in message.author.roles]:
           await client.delete_message(message)
           await client.send_message(message.channel, "Sorry mate only trusted members or bots can attach things to prevent spam")**

在不了解完整代码的情况下,此代码段似乎接近实现您想要的操作,它只是第二个
if
错误并导致问题的情况

假设用相应的bot和受信任角色ID替换
*roleID*
roleID
*roleID*
将始终返回
True
,无论您在字符串中输入了什么,因为它不是空的。此时,
中正确的内容几乎被忽略,
if
语句将始终返回
True
,删除通过这段代码的任何消息

另一件需要注意的事情是,您应该使用您为两个
roleID
检查所做的列表理解,而不仅仅是一个检查,因此您必须将其保存到一个变量中

尝试查看以下各项是否有效:

if len(message.attachments) > 0:
    author_roles = [role.id for role in message.author.roles]
    # replace both botRoleId and trustedRoleID with the respective IDs (as strings, because role.id is a string as well)
    if "botRoleID" not in author_roles or "trustedRoleID" not in author_roles:
        await client.delete_message(message)
        await client.send_message(message.channel, "Sorry mate only trusted members or bots can attach things to prevent spam")

我希望我能帮忙

多谢各位。它可以删除图像,但角色验证似乎不起作用。但这比我所拥有的要好,所以谢谢你的帮助:)