如何使用discord.py重写分配角色? [英] How do you assign roles with the discord.py rewrite?
本文介绍了如何使用discord.py重写分配角色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 discord.py
重写创建一个不和谐的bot,并将其托管在repl.it上。我正在尝试添加角色分配,但是每次尝试添加角色时都会出现错误
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'
推荐答案
我添加了Alberto Poljak的建议,它起作用了!
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)
这篇关于如何使用discord.py重写分配角色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文