如何让我的机器人 remove/delete 在 discord.py 中扮演角色?

How do I make my bot remove/delete roles in discord.py?

@client.command()
async def removerole(ctx, *, role: discord.Role = None):
    if ctx.author.guild_permissions.administrator and role:
        guild = ctx.guild
        await guild.delete_role(role.guild, name=role)
        await ctx.send(f"""{ctx.author.mention} The role has been deleted""")
    else:
        await ctx.send(f"""Sorry {ctx.author.mention}, you either don't have the administrator permissions or you misspelled or did not include the name of the role you would like to remove.""")

这是我的 removerole 命令的当前代码。我的代码要么写错了,要么 delete_role 已在最新版本的 discord.py 重写中删除,因为我收到此错误

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Guild' object has no attribute 'delete_role'

希望有人能帮助我:>

discord.Guild 没有 delete_role 功能。这是一种方法:

@client.command()
async def removerole(ctx, *, role: discord.Role = None):
    if ctx.author.guild_permissions.administrator and role:
        guild = ctx.guild
        if role in guild.roles: # Check if role is in the guild
            await role.delete()
            await ctx.send(f"""{ctx.author.mention} The role has been deleted""")
            return

    await ctx.send(f"""Sorry {ctx.author.mention}, you either don't have the administrator permissions or you misspelled or did not include the name of the role you would like to remove.""")