Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 检查用户是否具有角色_Python_Discord_Discord.py - Fatal编程技术网

Python 检查用户是否具有角色

Python 检查用户是否具有角色,python,discord,discord.py,Python,Discord,Discord.py,我正在检查用户是否具有特定角色。我知道@commands.has_role(),但这对我正在制作的内容不起作用。我有下面的示例代码,我不确定如何让它检查用户是否拥有该角色 @commands.command() 异步def hasthisroletest(自身,ctx): 如果ctx.author.role.id==74683126883186268: 等待ctx.send(“你做到了!”) 其他: 等待ctx发送(“否:(”) 您可以检查想要的角色是否存在 用于获取角色本身 @commands

我正在检查用户是否具有特定角色。我知道@commands.has_role(),但这对我正在制作的内容不起作用。我有下面的示例代码,我不确定如何让它检查用户是否拥有该角色

@commands.command()
异步def hasthisroletest(自身,ctx):
如果ctx.author.role.id==74683126883186268:
等待ctx.send(“你做到了!”)
其他:
等待ctx发送(“否:(”)
您可以检查想要的角色是否存在

用于获取角色本身

@commands.command()
异步def hasthisroletest(ctx):
#您还可以使用name='Test_role'
role=discord.utils.get(ctx.guild.roles,id=74683126883186268)
如果角色在ctx.author.roles中:
等待ctx.send(“你做到了!”)
其他:
等待ctx发送(“否:(”)

您制作的内容的背景是什么?