AttributeError:“Bot”对象没有属性“add_roles”

Dex*_*ter 3 python discord discord.py

我正在用 Python 编写一个用于discord 的机器人。我希望当有人登录到服务器时,他被赋予一定的角色

\n\n
import discord\nfrom discord.ext import commands\nfrom discord.ext.commands import bot\nbot = commands.Bot(command_prefix=\'!\')\nfrom discord.utils import get\n\n@bot.event\nasync def on_member_join(member):\n    role = get(member.roles, name="\xd0\x98\xd0\xb3\xd1\x80\xd0\xbe\xd0\xba\xd0\xb8")\n    await bot.add_roles(member, role)\n
Run Code Online (Sandbox Code Playgroud)\n\n

当我启动并且有人进入服务器时,出现以下错误:\nAttributeError: \'Bot\' object has no attribute \'add_roles\'

\n

Pat*_*ugh 5

确保您使用的是最新版本的文档。您应该从公会获得角色并使用Member.add_roles

\n\n
@bot.event\nasync def on_member_join(member):\n    role = get(member.guild.roles, name="\xd0\x98\xd0\xb3\xd1\x80\xd0\xbe\xd0\xba\xd0\xb8")\n    await member.add_roles(role)\n
Run Code Online (Sandbox Code Playgroud)\n