问题描述
这应该检查特定的人是否具有静音角色
this should check if the specific person does or doesn't have the mute role
@bot.command(pass_context=true) @commands.has_role("*****") async def unmute(ctx, user: discord.member): role = discord.utils.find(lambda r: r.name == 'member', ctx.message.server.roles) if user.has_role(role): await bot.say("{} is not muted".format(user)) else: await bot.add_roles(user, role)
抛出此错误
命令引发异常:attributeerror: 'member' object has no attribute 'has_role'
command raised an exception: attributeerror: 'member' object has no attribute 'has_role'
我不知道该怎么做,所以我非常感谢我能得到的每一个帮助
i don't know how to do it so i would really appreciate every help i can get
推荐答案
成员没有 .has_role() 方法,但是您可以使用 获取他们所有角色的列表.角色.
member does not have a .has_role() method, you can however get a list of all their roles using .roles.
要查看用户是否具有给定角色,我们可以使用 role in user.roles.
to see if a user has a given role we can use role in user.roles.
@bot.command(pass_context=true) @commands.has_role("*****") async def unmute(ctx, user: discord.member): role = discord.utils.find(lambda r: r.name == 'member', ctx.message.guild.roles) if role in user.roles: await bot.say("{} is not muted".format(user)) else: await bot.add_roles(user, role)
参考文档:https://discordpy.readthedocs.io/en/最新/api.html#member
注意: ctx.message.guild.roles 使用 ctx.message.server.roles.由于 api 更改而更新.
note: ctx.message.guild.roles use to be ctx.message.server.roles. updated due to api change.