[英]Check if a user has a role
我正在尝试检查用户是否具有特定角色。 我知道@commands.has_role(),但这不适用于我正在制作的内容。 我有下面的示例代码,我不确定如何让它检查用户是否具有该角色。
@commands.command()
async def hasthisroletest(self, ctx):
if ctx.author.role.id == 746831268683186268:
await ctx.send("You did it!")
else:
await ctx.send("Nope :(")
如果想要的角色在那里,您可以检查Member.roles 。
使用discord.utils.get获取角色本身。
@commands.command()
async def hasthisroletest(ctx):
# you can also use name = 'Test_role'
role = discord.utils.get(ctx.guild.roles, id=746831268683186268)
if role in ctx.author.roles:
await ctx.send("You did it!")
else:
await ctx.send("Nope :(")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.