python - 如何以简单的方式删除所有不和谐角色?
问题描述
我有一堆服务器,我想删除我之前创建的所有角色,但它们的数量还有很多不足之处......
而不是传统上提到的角色(这是有缺陷的,而且很慢),我无法找到如何对其进行编码,以便可以运行命令并且可以自动删除机器人下面的所有角色。
我想出的代码:
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,这是您的固定代码:
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的文档
推荐阅读
- ms-access-2016 - 错误您尝试打开的数据库需要更新版本的 Microsoft Access
- java - Spring boot如何实现Error页面
- gremlin - 如何排除不包含值的顶点
- c++ - 如何为给定的测试用例解决这个 geeksforgeeks 问题?
- javascript - Highchart 根据 y 轴的值改变十字准线颜色
- algorithm - 以下程序的时间复杂度是多少?
- output - 问题:带有附加 1 的 plm 包虚拟变量的输出
- azure - 如何获取 azure 管道的最后运行 id?
- imagemagick - 识别命令输出中的颜色图和直方图有什么区别?
- nginx - www 在域中返回超时,在我在 nginx 中使用正则表达式添加重定向之后