【问题标题】:How to delete a role with discord.py?如何使用 discord.py 删除角色?
【发布时间】:2020-04-09 09:44:24
【问题描述】:

使用以下代码行:

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

我得到错误:

【问题讨论】:

标签: python python-3.x discord discord.py


【解决方案1】:

您使用的是 discord.py v0.16 中不再受支持的过时语法。
请参阅migration guide for v1,具体如何Server is now Guild

您也可以直接从Context object's guild attribute 获取公会,而不是通过其message 属性。

此外,除非您已覆盖 Context,否则它不会有 delete_role 方法。
您需要改用Role.delete 方法。

有关降价的帮助,请参阅https://stackoverflow.com/editing-help

【讨论】:

    猜你喜欢
    • 2019-02-12
    • 1970-01-01
    • 2020-08-03
    • 1970-01-01
    • 2021-10-10
    • 1970-01-01
    • 2021-11-06
    • 2019-01-22
    • 2021-07-31
    相关资源
    最近更新 更多