gpt4 book ai didi

python - 属性错误 : 'Bot' object has no attribute 'add_roles'

转载 作者:行者123 更新时间:2023-12-04 01:37:19 24 4
gpt4 key购买 nike

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

import discord
from discord.ext import commands
from discord.ext.commands import bot
bot = commands.Bot(command_prefix='!')
from discord.utils import get

@bot.event
async def on_member_join(member):
role = get(member.roles, name="Игроки")
await bot.add_roles(member, role)

当我启动并且有人进入服务器时,出现以下错误:AttributeError: 'Bot' 对象没有属性 'add_roles'

最佳答案

确保您使用的是 latest version of the documentation .您应该从行会获得角色并使用 Member.add_roles

@bot.event
async def on_member_join(member):
role = get(member.guild.roles, name="Игроки")
await member.add_roles(role)

关于python - 属性错误 : 'Bot' object has no attribute 'add_roles' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59052536/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com