Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何用简单的方法删除所有不和谐的角色?_Python_Discord_Discord.py - Fatal编程技术网

Python 如何用简单的方法删除所有不和谐的角色?

Python 如何用简单的方法删除所有不和谐的角色?,python,discord,discord.py,Python,Discord,Discord.py,我有一堆服务器,我想删除我以前扮演的所有角色,但它们的数量还有很多需要改进的地方 与传统上提到的角色不同(这是有缺陷的,而且速度很慢),我无法找到如何对其进行编码,以便可以运行命令并自动删除bot下面的所有角色 我想出的代码是: async def delrole(ctx, *, roles: discord.Role): for role in roles: try: await client.delete_role(ctx.message.gu

我有一堆服务器,我想删除我以前扮演的所有角色,但它们的数量还有很多需要改进的地方

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

我想出的代码是:

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!")

任何意见都将不胜感激!谢谢

您正在使用旧的discord.py异步版本,下面是您的固定代码:

对于ctx.guild.roles中的角色:
尝试:
等待角色。删除()
不和谐除外。禁止:
等待ctx.send(f'无法删除此角色{role}')

请阅读discord.py rewrite

这是真的,但并没有真正回答他的问题。他希望能够删除所有角色而不必提及它们