cdnAshton
cdnAshton

Reputation: 29

Discord py Add role on command

Hey Im trying to make a command where If someone types ">verify" it adds the role called "Member" to them.

@client.command(pass_context=True)
    async def verify(ctx):
    member = ctx.message.author
    role = get(member.guild.roles, name="Member")
    await client.add_roles(member, role)

That is the code I currently have. I have already looked here for answers but none have worked so far.

Upvotes: 0

Views: 121

Answers (1)

itzFlubby
itzFlubby

Reputation: 2289

You're using the wrong function. Try using discord.Member.add_roles() instead.

@client.command(pass_context=True)
async def verify(ctx):
    member = ctx.message.author
    role = get(member.guild.roles, name="Member")
    await member.add_roles(role)

I'm also guessing you explicitly imported get from discord.utils? Otherwise you would need to call the function via

role = discord.utils.get(member.guild.roles, name="Member")

Upvotes: 1

Related Questions