示例#1
0
    async def removerole(self, ctx, user: discord.Member, *, rolename):
        """Removes an role from someone."""
        role = None
        #mention
        if rolename.startswith("<@"):
            roleid = rolename.replace('<', '').replace('!', '').replace(
                '@', '').replace('&', '').replace('>', '')
            role = discord.utils.get(ctx.guild.roles, id=int(roleid))
        #id
        elif rolename.isdigit():
            role = discord.utils.get(ctx.guild.roles, id=int(rolename))
        #name
        else:
            name = difflib.get_close_matches(rolename,
                                             Util.getRoleNameArray(ctx), 1,
                                             0.4)
            if len(name) > 0:
                role = discord.utils.get(ctx.guild.roles,
                                         id=Util.getRoleIdDict(ctx)[name[0]])

        if role is None:
            await ctx.send("I cannot find that role!")
            return
        try:
            await user.remove_roles(role)
            await ctx.send(
                f":ok_hand: I removed the {rolename} role from {user}!")
        except discord.Forbidden:
            await ctx.send("I need **Manage Roles** for this!")
示例#2
0
    async def leave(self, ctx: commands.Context, *, rolename):
        """Leaves one of the selfrole groups you are in"""
        role = None
        #mention
        if rolename.startswith("<@"):
            roleid = rolename.replace('<', '').replace('!', '').replace(
                '@', '').replace('&', '').replace('>', '')
            role = discord.utils.get(ctx.guild.roles, id=int(roleid))
        #id
        elif rolename.isdigit():
            role = discord.utils.get(ctx.guild.roles, id=int(rolename))
        #name
        else:
            name = difflib.get_close_matches(rolename,
                                             Util.getRoleNameArray(ctx), 1,
                                             0.4)
            if len(name) > 0:
                role = discord.utils.get(ctx.guild.roles,
                                         id=Util.getRoleIdDict(ctx)[name[0]])

        if role is None:
            await ctx.send("I cannnot find that role!")
            return

        role_id_list = Configuration.getConfigVar(ctx.guild.id,
                                                  "JOINABLE_ROLES")
        if role.id in role_id_list and role in ctx.author.roles:
            await ctx.message.author.remove_roles(
                role,
                reason=f"{ctx.message.author} Left role group {role.name}")
            await ctx.send(f"Succesfully left {role.name}")
        else:
            await ctx.send(
                "That role isn't leavable or you don't have the role.")