【问题标题】:How do I add roles in discord.py in latest version?如何在最新版本的 discord.py 中添加角色?
【发布时间】:2021-03-16 14:12:18
【问题描述】:

这是代码:

@bot.event
async def on_ready():
    print('We have logged in as {0.user}'.format(bot))
    moji = await bot.get_channel(775355712271941647).send("react to get banana")
    await moji.add_reaction(emoji='????')


@bot.event
async def on_reaction_add(reaction, user):

    if reaction.emoji == "????":
        role = discord.utils.get(user.guild.roles, name="banana")
        await user.add_role(role)

这是错误:

AttributeError: 'Member' object has no attribute 'add_role'

我到处搜索,但每个答案都告诉我做user.add_role。我也查了文档,没找到。请帮忙。哦,还有,client.add_role(user, name) 也不起作用

【问题讨论】:

  • await user.add_role(role) > 改成await user.add_roles(role)
  • @Sofia 谢谢,它解决了我的问题,哈哈

标签: python-3.x discord.py roles


【解决方案1】:

Member 对象包含add_roles 的属性。

add_role 更改为add_roles 应该可以解决此问题:

await user.add_roles(role)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-21
    • 2018-06-21
    • 2021-07-26
    • 2021-03-26
    • 2021-07-06
    • 1970-01-01
    • 2021-07-20
    相关资源
    最近更新 更多