Answers for "give member a role discord py"

1

discord.py add role on member join

intents = discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix=',', intents=intents)

@client.event 
async def on_member_join(member):
  role = get(member.guild.roles, id=role_id)
  await member.add_roles(role)
Posted by: Guest on February-01-2021
3

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

Python Answers by Framework

Browse Popular Code Answers by Language