Reputation: 45
I want to create a command that assigns a role to a user - e.g. !role [role] [User]
I searched the internet for hours, but only found commands that give the author of the message a role. Here's my code:
@client.command(pass_context=True)
async def role(ctx, role):
member = #What must I write here?
if role is None:
await ctx.send("You have not specified a role")
else:
test = discord.utils.get(member.guild.roles, name=role)
await discord.Member.add_roles(member, test)
await ctx.send("Role added")
Upvotes: 2
Views: 177
Reputation: 943
Try using this -
@client.command()
async def role(ctx, member : discord.Member, role : discord.Role):
await member.add_roles(role)
Usage - !role [Member] [Role]
Upvotes: 2
Reputation: 4743
Here you can try this
@client.command(pass_context=True)
async def rol(ctx, role, member: discord.Member):
role = discord.utils.get(member.guild.roles, name=role)
member.add_role(role)
await ctx.send("role added")
Upvotes: 0