discord python give user role code example
Example 1: add self role with discord bot python
@async def on_message(message):
if message.content == "give me admin"
role = discord.utils.get(server.roles, name="Admin")
await client.add_roles(message.author.id, role)
Example 2: discord.py check if user has role
@bot.command(pass_context=True)
@commands.has_role("Admin")
async def unmute(ctx, user: discord.Member):
role = discord.utils.find(lambda r: r.name == 'Member', ctx.message.server.roles)
if role in user.roles:
await bot.say("{} is not muted".format(user))
else:
await bot.add_roles(user, role)