如何检查成员是否具有角色discord.py

时间:2020-08-17 09:01:51

标签: python discord.py

我要执行“警告”命令,并且要检查成员是否具有角色。 我的代码:

async def пред(ctx, member: discord.Member = None, *, reason=None):
    р.Персонал=discord.utils.find(lambda r: r.id == '701381413215141948', ctx.message.server.roles)
    if р.Персонал not in member.roles:
        print("You don't have role")
        return
    else:
        print('Success')

错误:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: Att
ributeError: 'Message' object has no attribute 'server'

1 个答案:

答案 0 :(得分:0)

问题为InsertChessyLine,应该是ctx.guild.roles而不是ctx.message.server.roles

async def пред(ctx, member: discord.Member = None, *, reason=None):
    р.Персонал=discord.utils.find(lambda r: r.id == '701381413215141948', ctx.guild.roles)
    if р.Персонал not in member.roles:
        print("You don't have role")
        return
    else:
        print('Success')