Skip to content
Advertisement

How to check if member has role discord.py

I want to make a “warn” command and I want to check if member has role. My code:

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')

Error:

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

Advertisement

Answer

The issue as InsertChessyLine it should be ctx.guild.roles instead of 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')
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement