【问题标题】:How do I remove all discord roles?如何删除所有不和谐角色?
【发布时间】:2020-12-21 13:38:18
【问题描述】:

我有几台服务器,我想删除我之前创建的所有角色,但它们的数量还有很多不足之处.. 我创建了一个删除一个角色的命令。请帮助创建一个将从服务器不和谐中删除所有角色的命令

@client.command(pass_context=True)
async def delrole(ctx, *,role_name):
  role = discord.utils.get(ctx.message.server.roles, name=role_name)
  if role:
    try:
      await client.delete_role(ctx.message.server, role)
      await client.say("The role {} has been deleted!".format(role.name))
    except discord.Forbidden:
      await client.say("Missing Permissions to delete this role!")
  else:
    await client.say("The role doesn't exist!")

【问题讨论】:

  • for role in ctx.message.server.roles: [your deletion logic here] 应该没问题

标签: python discord discord.py


【解决方案1】:

正如 Lukas Thaler 所说,您可以循环浏览服务器中的所有角色,但如果您只想删除一些角色,您可以试试这个。

@client.command()
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("Missing Permissions to delete this role!")

使用此命令的格式为:!delrole @role1 @role2 @role3 等。任意多个角色都可以。

【讨论】:

    猜你喜欢
    • 2021-01-16
    • 2021-10-19
    • 1970-01-01
    • 2021-09-20
    • 2021-01-05
    • 2022-10-24
    • 2020-10-16
    • 2018-10-22
    • 1970-01-01
    相关资源
    最近更新 更多