python - Discord.py - 从服务器复制角色(名称和颜色)
问题描述
我正在尝试创建服务器的副本,就像我在服务器中 > 复制一样,它将创建一个具有相同名称但添加“备份”的新服务器,然后它复制所有通道、角色和权限。
我设法使复制渠道(和类别)工作,如果可以的话,我计划稍后再做。目前,我正在尝试复制角色(名称和颜色)
@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())
它目前创建具有随机颜色和名称的角色role
,有没有人做过类似的事情,可以告诉我如何获取原始服务器每个角色的名称和颜色?
解决方案
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
:) 希望这会有所帮助
推荐阅读
- pentaho - 如何使用 Pentaho 数据集成 (PDI) 将 Sqlite 数据传输到 Mysql?
- android - 使用谷歌浏览器远程调试我的安卓设备没有显示浏览器检查
- flutter - 如何从飞镖文件中调用graphQl“查询”
- ios - 如何将 imageView 作为源传递给 QuickLook 预览
- php - 未捕获的类型错误:ajax jquery 中的非法调用
- deep-learning - 如何选择用于我的模型的预训练权重?
- android - 像 Messenger 应用中一样的 Android 图库照片选择器
- json - 如何在python 3中比较两个嵌套的json
- python - 在 Python 中处理 minimummodbus 异常
- mongodb - SpringBoot ReactiveMongoTemplate 部分更新文档