问题
I am creating a discord bot using discord.py
rewrite and am hosting iton repl.it. I am trying to add assignment of roles, but I get an error everytime I try to add it
I'be looked around stack overflow and have been unable to find a solution to adding roles. I've also looked through the documentation, but that just made me more confused.
import discord.utils
@client.command()
async def role(ctx, * role):
user = ctx.message.author
role = discord.utils.get(user.guild.roles, name=f"{role}")
await ctx.add_roles(user, role)
It should add the specified role to the message author but it just produces this error
File "main.py", line 18, in role
await ctx.add_roles(user, role)
AttributeError: 'Context' object has no attribute 'add_roles'
回答1:
I added Alberto Poljak's suggestions and it worked!
import discord.utils
@client.command()
async def role(ctx, * role: discord.Role):
user = ctx.message.author
await user.add_roles(role)
来源:https://stackoverflow.com/questions/56451752/how-do-you-assign-roles-with-the-discord-py-rewrite