如何使我的漫游器在discord.py中删除/删除角色?

时间:2020-07-20 07:43:46

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

@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命令的当前代码。我执行了错误的代码,或者在最新版本的discord.py rewrite中删除了delete_role,因为出现此错误

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

我希望有人能够帮助我:>

1 个答案:

答案 0 :(得分:1)

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.""")