Discord.py: Adding role

Created on 5 Feb 2018  路  2Comments  路  Source: Rapptz/discord.py

Hey, I would like my bot to give a role via command. I did it but it does not work. I would ask for help.

code:
import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio

@bot.command(pass_context=True)#?
async def role (ctx, userName: discord.User):
await bot.add_roles(userName, name='test')

bot.run()

question

Most helpful comment

discord.Role is a converter in which you can pass as an argument in your command to add a role to persay, a bot or a user: For instance:
async def role(ctx, user: discord.User, role: discord.Role):

All 2 comments

Add_roles does not take in a kwarg "name", it takes in an argument list of role objects. You can get these by iterating through server.roles- discord.utils.get() is helpful for this.

discord.Role is a converter in which you can pass as an argument in your command to add a role to persay, a bot or a user: For instance:
async def role(ctx, user: discord.User, role: discord.Role):

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jzburda picture jzburda  路  3Comments

j0hnmeow picture j0hnmeow  路  3Comments

Yolotroll101 picture Yolotroll101  路  3Comments

Rimmy50 picture Rimmy50  路  3Comments

PicklesJars picture PicklesJars  路  3Comments