AttributeError: 'Bot' object has no attribute 'add_roles'

那年仲夏 提交于 2021-02-05 11:29:35

问题


I am writing a bot for discord in Python. I want that when someone logged in to the server, he was given a certain role

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)

When I start and someone enters the server, I get the following error: AttributeError: 'Bot' object has no attribute 'add_roles'


回答1:


Make sure you're using the latest version of the documentation. You should be getting the role from the guild and using Member.add_roles

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


来源:https://stackoverflow.com/questions/59052536/attributeerror-bot-object-has-no-attribute-add-roles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!