问题
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