Discord.py Add Role To User
I am new to python and creating discord bots in general and I can't for the life of me figure out how to make my bot assign a role to a user upon the users request. I have scoured
Solution 1:
For the rewrite version things have changed a little bit, add_roles
is no more part of client
but part of the discord.Member
class therefor the code for the discord.py rewrite version is:
@client.command(pass_context=True)
async def add_role(ctx):
member = ctx.author
role = discord.utils.get(member.guild.roles, name="Bots")
await member.add_roles(role)
A minor update for the REWRITE version.
Solution 2:
Remove the has_role
check. It doesn't make sense to check if the caller has a role so they can assign themselves that role.
@client.command(pass_context=True)
async def add_bot(ctx):
member = ctx.message.author
role = discord.utils.get(member.server.roles, name="Bots")
await client.add_roles(member, role)
Post a Comment for "Discord.py Add Role To User"