我是discord api的新手,我想为不和谐的机器人。我想发出一个更改角色颜色的命令。 我使用以下代码更改颜色:
class MyClient(discord.Client):
async def on_message(self, message):
server = client.get_guild('')
for role in server.roles:
if role.name == 'Цвет':
await client.edit_role(server=server, role=role, colour=0x0080000)
break
我遇到2个错误:
Instance of 'MyClient' has no 'edit_role' member
File ".\mybot.py", line 10, in on_message
for role in server.roles:
AttributeError: 'NoneType' object has no attribute 'roles'
答案 0 :(得分:0)
您正在查看过时的API文档,请参阅:https://discordpy.readthedocs.io/en/latest/migrating.html?highlight=edit_role
在v1.0之前使用 Client.edit_role()
。您需要一个Role类的实例并执行Role.edit()
https://discordpy.readthedocs.io/en/latest/api.html?highlight=role#discord.Role.edit
async def on_message(self, message):
server = client.get_guild('')
for role in server.roles:
if role.name == 'Цвет':
await role.edit(color=0x080000)