Sorry for being late on this but the answer is simple. Your code is fine just when typing the command use
(prefix) @user mention @role
Ex. !addrole @huss_a @example
I would also recommended putting @commands.has_permissions reference at the beginning so only admins can use this and users can't give themselves any role they want like so:
@bot.command()
@commands.has_permissions(manage_roles=True)
async def addrole(ctx, member: discord.Member, role: discord.Role):
await member.add_roles(role)
await ctx.send(f"{member} now had the {role} role")
You can also use this code:
@bot.command()
@commands.has_permissions(manage_roles=True)
async def addrole(ctx, role: discord.Role, user: discord.Member):
await user.add_roles(role)
await ctx.send(f"{role.mention} was added to {user.mention})
Lemonpy
and I typelemonpy
for the member name it won't find me and the code won't work. – Lemon.py