AttributeError:'Bot'对象没有属性'add_roles'

时间:2019-11-26 13:56:30

标签: python discord discord.py

我正在用Python写一个不和谐的机器人。我希望当有人登录服务器时,赋予他特定角色

import docx
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
from docx.shared import Inches,Cm,Mm
import lorem

new_document = docx.Document()



table = new_document.add_table(rows=1,cols=2)

pic_cel = table.rows[0].cells[0].add_paragraph()
run = pic_cel.add_run()
run.add_picture("Image.jpg",width = Mm(45),height = Mm(45))

text = table.rows[0].cells
text[0].width = Inches(50)
text[1].text = 'kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk'
new_document.save("test.docx")

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

1 个答案:

答案 0 :(得分:0)

确保您使用的是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)