Answers for "how to get the roles of a user using discord.py"

4

discord.py how to give a user a role

# If ctx is not defined and you are handling a message, use this code
ctx = await bot.get_context(message)

# This is the code needed to give a user a role
member = ctx.message.author # Member object that you want to add the role to
role = discord.utils.get(lambda role: role.name == "Role Name", ctx.guild.roles) # The role object
await member.add_roles(role) # Adds the role to the member
Posted by: Guest on June-24-2021
2

how to get the author on discord.py

ctx.author #Gets the author of a command
ctx.author.id #Gets the Discord ID of the author of a command
Posted by: Guest on March-29-2021

Code answers related to "how to get the roles of a user using discord.py"

Python Answers by Framework

Browse Popular Code Answers by Language