如何一次删除所有角色(Discord.py 1.4.1)

时间:2020-08-22 13:57:09

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

我尝试制作一条添加“囚犯”角色并删除目标用户具有的所有角色的命令

    @commands.has_permissions(administrator=True)
    async def prison(self, ctx, member: discord.Member):
        """Imprison offender"""
        role = discord.utils.get(ctx.guild.roles, name='Prisoner')
        await member.add_roles(role)
        await member.remove_roles()
        await ctx.message.add_reaction(emoji=self.tick)
        await ctx.send(f"{member} is imprisoned!")

    @prison.error
    async def prison_error(ctx, error):
      if isinstance(error, commands.MissingPermissions):
        await ctx.send("Sorry you're not allowed to use this command. This command is only for the Server's authorities.")

1 个答案:

答案 0 :(得分:0)

要添加“囚犯”角色,然后再删除每个角色。尝试另一种方法

    @commands.has_permissions(administrator=True)
    async def prison(self, ctx, member: discord.Member):
        """Imprison offender"""
        role = discord.utils.get(ctx.guild.roles, name='Prisoner')
        await member.remove_roles(member.roles) # remove all member roles before
        await member.add_roles(role) # then add the new role
        await ctx.message.add_reaction(emoji=self.tick)
        await ctx.send(f"{member} is imprisoned!")