Add [p]warnings server command to list all warnings in a guild (#5862)

Co-authored-by: Jakub Kuczys <me@jacken.men>
This commit is contained in:
Michael Oliveira
2026-05-18 20:03:59 -04:00
committed by GitHub
parent d5b816d360
commit eb77211eb8
+36 -2
View File
@@ -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):