首页 > 解决方案 > 如何检查作者是否在 x 服务器中具有 x 角色?

问题描述

我正在尝试检查作者是否在 x 服务器上具有 x 角色以便能够使用该命令但无法使其工作。我只能检查 Author 在该服务器中是否具有 x 角色。

想法:如果用户在 x 服务器中具有 x 角色,将能够在任何服务器上使用特殊命令。

 role_id = 569712344226201600
 author = ctx.message.author

 if role_id in [role.id for role in author.roles]:
     await ctx.send("message")

标签: pythonpython-3.xdiscord.pydiscord.py-rewrite

解决方案


您可以只获取角色对象。

role = discord.utils.get(ctx.guild.roles, id=role_id_here)

然后只是:

if role in ctx.author.roles:
...

您的机器人必须在这些服务器上。


推荐阅读