【问题标题】:Discord.py how to delete all roles in serverDiscord.py如何删除服务器中的所有角色
【发布时间】:2021-10-19 12:41:05
【问题描述】:

我正在尝试删除我的 discord 服务器中的所有角色,但这需要大量时间。所以我决定用discord.py bot 来完成这个任务,但是我得到了这个错误:

discord.errors.HTTPException: 400 Bad Request (error code: 50028): Invalid Role

这是我的代码:

@client.command()
async def delroles(ctx):
 for role in ctx.guild.roles:  
     await role.delete()

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    问题是所有用户都有一个名为@everyone的“隐形角色”,无法删除。

    做:

    async def delroles(ctx):
     for role in ctx.guild.roles:  
         try:  
            await role.delete()
         except:
            await ctx.send(f"Cannot delete {role.name}")
    

    【讨论】:

    • 非常感谢,兄弟)帮了大忙
    猜你喜欢
    • 2021-07-16
    • 1970-01-01
    • 2019-02-12
    • 1970-01-01
    • 2021-01-16
    • 2021-04-01
    • 1970-01-01
    • 2020-08-03
    • 1970-01-01
    相关资源
    最近更新 更多