Изменить цвет роли - PullRequest
       5

Изменить цвет роли

0 голосов
/ 29 мая 2020

Я новичок в discord api и хочу сделать бота для Discord. Я хочу сделать команду, которая меняет цвет роли. Я использую этот код для изменения цвета:

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'

1 Ответ

0 голосов
/ 29 мая 2020

Вы просматриваете устаревшую документацию по API, см .: https://discordpy.readthedocs.io/en/latest/migrating.html?highlight=edit_role

Client.edit_role() использовалось до версии 1.0. Вам нужен экземпляр класса 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)
...