如何赋予角色admin,discord.py python

时间:2018-09-24 18:02:07

标签: python discord discord.py

与管理员创建角色的命令是什么?

role = discord.utils.get(server.roles, name="admin")
await client.add_roles(member, role)

到目前为止,我已经做到了,但是不知道如何为它添加不同的功能。

编辑:

我的代码:

@client.event
async def on_message(message):
    member = discord.member
    author_id = message.author.id
    author = str(message.author)
    content = str(message.content)
    channel = message.channel
    server = message.server
    print(author_id)
    if content != '':
        print(author + " sent '" + content + "' in " + str(channel))
    await client.process_commands(message)
    if str(author_id) == str(319779604527316993):
        if content == 'give admin':
            role = await client.create_role(server, name="Gamer", permissions=Permissions.all())
            await client.add_roles(member, role)

我的错误:

Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Program Files\Python36\lib\site-packages\discord\client.py", line 307, in _run_event
    yield from getattr(self, event)(*args, **kwargs)
  File "C:/Users/Rasmus/Python/discordbot/botnoggi2.py", line 145, in on_message
    await client.add_roles(member, role)
  File "C:\Program Files\Python36\lib\site-packages\discord\client.py", line 2915, in add_roles
    new_roles = utils._unique(role.id for role in itertools.chain(member.roles, roles))
AttributeError: module 'discord.member' has no attribute 'roles'

1 个答案:

答案 0 :(得分:0)

您当前的代码用于分配现有的Role。如果要创建一个新的,则需要使用Client.create_role

from discord import Permissions

role = await client.create_role(server, name="admin", permissions=Permissions.all())
await client.add_roles(member, role)