Discord.py | add role to someone

from discord.ext import commands
from discord.utils import get

bot = commands.Bot(command_prefix='!')

@bot.command(pass_context=True)
@commands.has_role("Admin") # This must be exactly the name of the appropriate role
async def addrole(ctx):
    member = ctx.message.author
    role = get(member.server.roles, name="Test")
    await bot.add_roles(member, role)

I think the only real mistake in your code is the lack of pass_context=True in the @bot.command decorator. You may have seen some code without this, but that likely belongs to the experimental “rewrite” branch of

Leave a Comment