From eb77211eb8d838270ef0e5741d045a2356a1ade0 Mon Sep 17 00:00:00 2001 From: Michael Oliveira <34169552+Flame442@users.noreply.github.com> Date: Mon, 18 May 2026 20:03:59 -0400 Subject: [PATCH] Add `[p]warnings server` command to list all warnings in a guild (#5862) Co-authored-by: Jakub Kuczys --- redbot/cogs/warnings/warnings.py | 38 ++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/redbot/cogs/warnings/warnings.py b/redbot/cogs/warnings/warnings.py index 2178e2898..a63ca4701 100644 --- a/redbot/cogs/warnings/warnings.py +++ b/redbot/cogs/warnings/warnings.py @@ -18,8 +18,8 @@ from redbot.core.bot import Red from redbot.core.commands import UserInputOptional, RawUserIdConverter from redbot.core.i18n import Translator, cog_i18n from redbot.core.utils import AsyncIter +from redbot.core.utils.chat_formatting import box, pagify, warning from redbot.core.utils.views import ConfirmView -from redbot.core.utils.chat_formatting import warning, pagify from redbot.core.utils.menus import menu @@ -598,7 +598,7 @@ class Warnings(commands.Cog): channel=None, ) - @commands.command() + @commands.group(invoke_without_command=True) @commands.guild_only() @commands.admin() async def warnings(self, ctx: commands.Context, member: Union[discord.Member, int]): @@ -640,6 +640,40 @@ class Warnings(commands.Cog): ), ) + @warnings.command(name="server", aliases=["guild"]) + @commands.guild_only() + @commands.admin() + async def warnings_server(self, ctx: commands.Context): + """List all members with warnings in this server.""" + settings = await self.config.all_members(guild=ctx.guild) + body_parts = [] + pages = [] + count_len = len(_("Count")) + 2 + points_len = len(_("Points")) + 2 + for member_id, warnings in settings.items(): + count_len = max(count_len, len(str(len(warnings["warnings"])))) + points_len = max(points_len, len(str(warnings["total_points"]))) + for member_id, warnings in settings.items(): + member = ctx.guild.get_member(member_id) + member_formatted = member_formatted = member.display_name if member else str(member_id) + count = len(warnings["warnings"]) + points = warnings["total_points"] + body_parts.append(f" {count:<{count_len}}{points:<{points_len}}{member_formatted:2}") + body = "\n".join(body_parts) + header = "# {count:{count_len}}{point:{points_len}}{name:2}\n".format( + count=_("Count"), + count_len=count_len, + point=_("Points"), + points_len=points_len, + name=_("Name"), + ) + for page in pagify(body, shorten_by=len(header) + 20): + pages.append(box(header + page, lang="md")) + if not pages: + await ctx.send(_("This server has no warnings yet.")) + return + await menu(ctx, pages) + @commands.command() @commands.guild_only() async def mywarnings(self, ctx: commands.Context):