如何一次删除所有角色(Discord.py 1.4.1) [英] How to remove all roles at once (Discord.py 1.4.1)

查看:76
本文介绍了如何一次删除所有角色(Discord.py 1.4.1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试制作一条将添加"Prisoner"的命令.角色,并删除目标用户拥有的所有角色

I try to make a command which would add "Prisoner" role, and remove all roles the targeted user has

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

推荐答案

您要添加囚犯"删除每个角色之前的角色.尝试另一种方法

You are adding the "Prisoner" roles before deleting every roles. Try the other way around

    @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!")

这篇关于如何一次删除所有角色(Discord.py 1.4.1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆