Discord.py-从服务器复制角色(名称和颜色)

时间:2020-09-07 14:02:56

标签: python python-3.x discord discord.py discord.py-rewrite

我正在尝试创建服务器副本,就像在服务器中复制副本一样,它将创建一个具有相同名称但添加“备份”的新服务器,然后复制所有通道,角色和权限

我设法使复制通道(和类别)正常工作,如果可以的话,我计划稍后再允许。目前,我正在尝试复制角色(名称和颜色)

struct ListNode * revll(struct ListNode *head, int k) {
        struct ListNode * prev = NULL;
        struct ListNode * curr = head;
        struct ListNode * tmp = NULL;
        int count = k;

        tmp = head;
        while (tmp && count) {
                count--;
                tmp = tmp->next;
        }
        if (count != 0) {
                return head;
        }

        while ((curr != NULL) && (count < k)) {
                tmp = curr->next;
                curr->next = prev;
                prev = curr;
                curr = tmp;
                count++;
        }

        if (tmp) {
                head->next = revll(tmp, k);
        }
        return prev;
}

它目前使用随机颜色和名称@SelfBot.command() async def copy(ctx): # b'\xfc' await ctx.message.delete() await SelgBot.create_guild(f'backup-{ctx.guild.name}') await asyncio.sleep(4) for g in SelfBot.guilds: if f'backup-{ctx.guild.name}' in g.name: for c in g.channels: await c.delete() for cate in ctx.guild.categories: x = await g.create_category(f"{cate.name}") for chann in cate.channels: if isinstance(chann, discord.VoiceChannel): await x.create_voice_channel(f"{chann}") if isinstance(chann, discord.TextChannel): await x.create_text_channel(f"{chann}") print(ctx.guild.roles) for role in ctx.guild.roles: await g.create_role(name='role', color=RandomColor()) 创建角色,有没有人做过类似的事情,并且可以告诉我如何获取原始服务器每个角色的名称和颜色?

1 个答案:

答案 0 :(得分:0)

for role in ctx.guild.roles:
                name = role.name
                print(name)
                color = role.colour
                print(color)
                perms = role.permissions
                print(perms)
                await g.create_role(name=name, permissions=perms, colour=color)

您可以通过执行role.name / role.colour来获得名称和颜色:)希望对您有所帮助