Discord.py 机器人创建角色问题

问题描述 投票:0回答:1

当我创建新角色时,它们是在机器人角色之上创建的。这使得他们的立场不可能改变。因为由于角色层次结构的原因,机器人没有执行此操作的权限。我不知道为什么会发生这种情况,有人有任何想法吗?我不知道代码在这里是否有帮助,因为我正在从 yaml 文件下载角色数据,但我将留下负责它的部分和 yaml 文件。

代码:

async def generate_role(guild):
    with open("cogs/ServerGenerator/patterns/default.yml", 'r', encoding='utf-8') as rFile:
        data = yaml.safe_load(rFile)

    for role_name, role_data in data['roles'].items():
        if role_name == "everyone":
            await guild.default_role.edit(permissions=discord.Permissions(**role_data.get('permissions', {})))
        else:
            new_role = await guild.create_role(
                name=role_data.get('name', None),
                color=int(role_data.get('color', None), 16),
                hoist=role_data.get('hoist', None),
                mentionable=role_data.get('mentionable', None),
                permissions=discord.Permissions(**role_data.get('permissions', {}))
            )

Yaml 文件:

roles:
  #Server Roles
  owner:
    name: "⋞ᴏᴡɴᴇʀ⋡"
    color: "e5e357"
    hoist: true
    mentionable: false
  administrator:
    name: "⋞ᴀᴅᴍɪɴ⋡"
    color: "ed0041"
    hoist: true
    mentionable: true
  moderator:
    name: "⋞ᴍᴏᴅ⋡"
    color: "73c65a"
    hoist: true
    mentionable: true
  booster:
    name: "⋞ʙᴏᴏsᴛᴇʀ⋡"
    color: "fb0399"
    hoist: true
    mentionable: true
  member:
    name: "⋞ᴍᴇᴍʙᴇʀ⋡"
    color: "03d998"
    hoist: true
    mentionable: true
  newbie:
    name: "⋞ɴᴇᴡʙɪᴇ⋡"
    color: "ccc7a"
    hoist: true
    mentionable: true
  #Gender
  male:
    name: "ᴍᴀʟᴇ"
    color: "007fff"
    hoist: false
    mentionable: true
  female:
    name: "ғᴇᴍ"
    color: "c601e2"
    hoist: false
    mentionable: true
  other:
    name: "ᴏᴛʜᴇʀ〳ɴᴏɴ ʙɪ〳ᴘʀᴇғᴇʀ ɴᴏᴛ ᴛᴏ sᴀʏ"
    color: "03d998"
    hoist: false
    mentionable: true
  #Pronouns
  he:
    name: "ʜᴇ〳ʜɪᴍ"
    color: "007fff"
    hoist: false
    mentionable: true
  she:
    name: "sʜᴇ〳ʜᴇʀ"
    color: "c601e2"
    hoist: false
    mentionable: true
  they:
    name: "ᴛʜᴇʏ〳ᴛʜᴇᴍ﹝+ᴏᴛʜᴇʀs﹞"
    color: "03d998"
    hoist: false
    mentionable: true
  #Age
  18:
    name: "⊰ᴀɢᴇ⊱﹝𝟷𝟾+﹞"
    color: "9659b6"
    hoist: false
    mentionable: true
  15:
    name: "⊰ᴀɢᴇ⊱﹝𝟷𝟻+﹞"
    color: "a060d0"
    hoist: false
    mentionable: true
  13:
    name: "⊰ᴀɢᴇ⊱﹝𝟷𝟹+﹞"
    color: "a77dc2"
    hoist: false
    mentionable: true

我尝试在创建角色后移动角色,但层次结构权限不允许。我不知道创建角色时如何设置角色的位置。我在网上找不到任何东西,所以我在这里写。

bot_role = guild.me.top_role
await new_role.edit(position=bot_role.position - 1)
python discord discord.py
1个回答
0
投票

我不知道具体原因,但在对 YAML 文件进行更改后,开始在 bot 角色下创建角色。 以下是我所做的更改:

roles:
  #Server Roles
  cat-server_roles:
    name: "┉┉➤ sᴇʀᴠᴇʀ ʀᴏʟᴇs ⋮"
    color: "6c6e7e"
    hoist: false
    mentionable: false
  owner:
    name: "⋞ᴏᴡɴᴇʀ⋡"
    color: "e5e357"
    hoist: true
    mentionable: false
  administrator:
    name: "⋞ᴀᴅᴍɪɴ⋡"
    color: "ed0041"
    hoist: true
    mentionable: true
  moderator:
    name: "⋞ᴍᴏᴅ⋡"
    color: "73c65a"
    hoist: true
    mentionable: true
  booster:
    name: "⋞ʙᴏᴏsᴛᴇʀ⋡"
    color: "fb0399"
    hoist: true
    mentionable: true
  member:
    name: "⋞ᴍᴇᴍʙᴇʀ⋡"
    color: "03d998"
    hoist: true
    mentionable: true
  newbie:
    name: "⋞ɴᴇᴡʙɪᴇ⋡"
    color: "ccc7a"
    hoist: true
    mentionable: true
  #Gender
  cat-gender:
    name: "┉┉┉┉➤ ɢᴇɴᴅᴇʀ ⋮"
    color: "6c6e7e"
    hoist: false
    mentionable: false
  male:
    name: "ᴍᴀʟᴇ"
    color: "007fff"
    hoist: false
    mentionable: true
  female:
    name: "ғᴇᴍ"
    color: "c601e2"
    hoist: false
    mentionable: true
  other:
    name: "ᴏᴛʜᴇʀ〳ɴᴏɴ ʙɪ〳ᴘʀᴇғᴇʀ ɴᴏᴛ ᴛᴏ sᴀʏ"
    color: "03d998"
    hoist: false
    mentionable: true
  #Pronouns
  cat-pronouns:
    name: "┉┉┉➤ ᴘʀᴏɴᴏᴜɴs ⋮"
    color: "6c6e7e"
    hoist: false
    mentionable: false
  he:
    name: "ʜᴇ〳ʜɪᴍ"
    color: "007fff"
    hoist: false
    mentionable: true
  she:
    name: "sʜᴇ〳ʜᴇʀ"
    color: "c601e2"
    hoist: false
    mentionable: true
  they:
    name: "ᴛʜᴇʏ〳ᴛʜᴇᴍ﹝+ᴏᴛʜᴇʀs﹞"
    color: "03d998"
    hoist: false
    mentionable: true
  #Age
  cat-age:
    name: "┉┉┉┉┉┉➤ ᴀɢᴇ ⋮"
    color: "6c6e7e"
    hoist: false
    mentionable: false
  18:
    name: "⊰ᴀɢᴇ⊱﹝𝟷𝟾+﹞"
    color: "9659b6"
    hoist: false
    mentionable: true
  15:
    name: "⊰ᴀɢᴇ⊱﹝𝟷𝟻+﹞"
    color: "a060d0"
    hoist: false
    mentionable: true
  13:
    name: "⊰ᴀɢᴇ⊱﹝𝟷𝟹+﹞"
    color: "a77dc2"
    hoist: false
    mentionable: true
  #default role
  everyone:

也许有字母显示之类的东西,我不知道。

© www.soinside.com 2019 - 2024. All rights reserved.