diff --git a/docs/cog_guides/admin.rst b/docs/cog_guides/admin.rst index bf4894661..fe1022c66 100644 --- a/docs/cog_guides/admin.rst +++ b/docs/cog_guides/admin.rst @@ -150,7 +150,7 @@ selfroleset add **Description** -Add a role to the list of selfroles. +Add a role, or a selection of roles, to the list of available selfroles. .. warning:: Members will be able to assign themselves the role. Make sure it doesn't give extra perms or anything that can break @@ -174,7 +174,7 @@ selfroleset remove **Description** -Removes a role from the list of selfroles. +Remove a role, or a selection of roles, from the list of available selfroles. **Arguments** diff --git a/redbot/cogs/admin/admin.py b/redbot/cogs/admin/admin.py index ac84350b8..bb76cde10 100644 --- a/redbot/cogs/admin/admin.py +++ b/redbot/cogs/admin/admin.py @@ -450,45 +450,64 @@ class Admin(commands.Cog): pass @selfroleset.command(name="add") - async def selfroleset_add(self, ctx: commands.Context, *, role: discord.Role): + async def selfroleset_add(self, ctx: commands.Context, *roles: discord.Role): """ - Add a role to the list of available selfroles. + Add a role, or a selection of roles, to the list of available selfroles. NOTE: The role is case sensitive! """ - if not self.pass_user_hierarchy_check(ctx, role): - await ctx.send( - _( - "I cannot let you add {role.name} as a selfrole because that role is higher than or equal to your highest role in the Discord hierarchy." - ).format(role=role) - ) - return - async with self.config.guild(ctx.guild).selfroles() as curr_selfroles: - if role.id not in curr_selfroles: - curr_selfroles.append(role.id) - await ctx.send(_("Added.")) + current_selfroles = await self.config.guild(ctx.guild).selfroles() + for role in roles: + if not self.pass_user_hierarchy_check(ctx, role): + await ctx.send( + _( + "I cannot let you add {role.name} as a selfrole because that role is" + " higher than or equal to your highest role in the Discord hierarchy." + ).format(role=role) + ) + return + if role.id not in current_selfroles: + current_selfroles.append(role.id) + else: + await ctx.send( + _('The role "{role.name}" is already a selfrole.').format(role=role) + ) return - await ctx.send(_("That role is already a selfrole.")) + await self.config.guild(ctx.guild).selfroles.set(current_selfroles) + if (count := len(roles)) > 1: + message = _("Added {count} selfroles.").format(count=count) + else: + message = _("Added 1 selfrole.") + + await ctx.send(message) @selfroleset.command(name="remove") - async def selfroleset_remove(self, ctx: commands.Context, *, role: SelfRole): + async def selfroleset_remove(self, ctx: commands.Context, *roles: SelfRole): """ - Remove a role from the list of available selfroles. + Remove a role, or a selection of roles, from the list of available selfroles. NOTE: The role is case sensitive! """ - if not self.pass_user_hierarchy_check(ctx, role): - await ctx.send( - _( - "I cannot let you remove {role.name} from being a selfrole because that role is higher than or equal to your highest role in the Discord hierarchy." - ).format(role=role) - ) - return - async with self.config.guild(ctx.guild).selfroles() as curr_selfroles: - curr_selfroles.remove(role.id) + current_selfroles = await self.config.guild(ctx.guild).selfroles() + for role in roles: + if not self.pass_user_hierarchy_check(ctx, role): + await ctx.send( + _( + "I cannot let you remove {role.name} from being a selfrole because that role is higher than or equal to your highest role in the Discord hierarchy." + ).format(role=role) + ) + return + current_selfroles.remove(role.id) - await ctx.send(_("Removed.")) + await self.config.guild(ctx.guild).selfroles.set(current_selfroles) + + if (count := len(roles)) > 1: + message = _("Removed {count} selfroles.").format(count=count) + else: + message = _("Removed 1 selfrole.") + + await ctx.send(message) @commands.command() @checks.is_owner() diff --git a/redbot/cogs/admin/converters.py b/redbot/cogs/admin/converters.py index f361acdc5..5a1cb800d 100644 --- a/redbot/cogs/admin/converters.py +++ b/redbot/cogs/admin/converters.py @@ -17,5 +17,7 @@ class SelfRole(commands.Converter): selfroles = await admin.config.guild(ctx.guild).selfroles() if role.id not in selfroles: - raise commands.BadArgument(_("The provided role is not a valid selfrole.")) + raise commands.BadArgument( + _('The role "{role_name}" is not a valid selfrole.').format(role_name=role.name) + ) return role