您如何使用 discord.py 重写分配角色?
How do you assign roles with the discord.py rewrite?
我正在使用 discord.py
重写创建一个 discord 机器人并在 repl.it 上托管它。我正在尝试添加角色分配,但每次尝试添加时都会出现错误
我查看了堆栈溢出,但未能找到添加角色的解决方案。我也查看了文档,但这让我更加困惑。
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)
它应该将指定的角色添加到消息作者,但它只是产生了这个错误
File "main.py", line 18, in role
await ctx.add_roles(user, role)
AttributeError: 'Context' object has no attribute 'add_roles'
我添加了 Alberto Poljak 的建议并且成功了!
import discord.utils
@client.command()
async def role(ctx, * role: discord.Role):
user = ctx.message.author
await user.add_roles(role)
我正在使用 discord.py
重写创建一个 discord 机器人并在 repl.it 上托管它。我正在尝试添加角色分配,但每次尝试添加时都会出现错误
我查看了堆栈溢出,但未能找到添加角色的解决方案。我也查看了文档,但这让我更加困惑。
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)
它应该将指定的角色添加到消息作者,但它只是产生了这个错误
File "main.py", line 18, in role
await ctx.add_roles(user, role)
AttributeError: 'Context' object has no attribute 'add_roles'
我添加了 Alberto Poljak 的建议并且成功了!
import discord.utils
@client.command()
async def role(ctx, * role: discord.Role):
user = ctx.message.author
await user.add_roles(role)