首页 > 解决方案 > 如何以简单的方式删除所有不和谐角色?

问题描述

我有一堆服务器,我想删除我之前创建的所有角色,但它们的数量还有很多不足之处......

而不是传统上提到的角色(这是有缺陷的,而且很慢),我无法找到如何对其进行编码,以便可以运行命令并且可以自动删除机器人下面的所有角色。

我想出的代码:

async def delrole(ctx, *, roles: discord.Role):
    for role in roles:
        try:
            await client.delete_role(ctx.message.guild, role)
        except discord.Forbidden:
            await client.say("Cannot delete this role!")

任何输入将不胜感激!谢谢

标签: pythondiscorddiscord.py

解决方案


您使用的是旧异步版本的 discord.py,这是您的固定代码:

for role in ctx.guild.roles:
    try:
        await role.delete()
    except discord.Forbidden:
        await ctx.send(f'Cannot delete this role {role}')

请阅读discord.py-rewrite的文档


推荐阅读