python - Discord.py 如何删除服务器中的所有角色

标签 python discord discord.py

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

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()

最佳答案

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

做:

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

关于python - Discord.py 如何删除服务器中的所有角色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68820168/

相关文章:

python - 如何禁止阻止我的机器人的不和谐成员?不和谐.py

python - NumPY:了解如何对数组矩阵中的每个 n 值求和

javascript - 您如何检查机器人是否被 ping 通?

带有语句 : storing context 的 Python

node.js - 有没有办法让我的机器人检查私信并将其发布到我服务器的 channel 中?

python - 如何为特定用户打开一个窗口 discord.py

python - 如何保存命令冷却时间?

python - 有没有办法在discord.py中接收其他用户给我的建议

python - 在不使用 python-libtorrent 下载 torrent 的情况下检索对等列表

python - 用日志数量而不是 %asctime 标记 python 记录器文件