如何分配角色不和.py重写?

2024-04-20 05:05:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用discord.py重写创建一个不和谐的bot,并正在托管iton更换. 我正在尝试添加角色分配,但每次尝试添加时都会出错

我在堆栈溢出周围找过了,但一直找不到添加角色的解决方案。我也看过文档,但这让我更加困惑。在

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)

它应该将指定的角色添加到消息作者,但它只会产生此错误

^{pr2}$

Tags: 文档pyimportclient角色堆栈botutils
1条回答
网友
1楼 · 发布于 2024-04-20 05:05:21

我加了阿尔贝托·波尔贾克的建议,结果奏效了!在

import discord.utils 
@client.command()
async def role(ctx, * role: discord.Role):
  user = ctx.message.author
  await user.add_roles(role)

相关问题 更多 >