Make few adjustments to [p]mywarnings and its docs (#6673)

This commit is contained in:
Jakub Kuczys
2026-03-04 21:57:52 +01:00
committed by GitHub
parent afe4e636b7
commit 1bfe2a78fa
2 changed files with 44 additions and 42 deletions

View File

@@ -347,7 +347,7 @@ warningset mywarnings sendtodms
.. code-block:: none .. code-block:: none
[p]warningset mywarnings_sendtodms <true_or_false> [p]warningset mywarnings sendtodms <true_or_false>
**Description** **Description**

View File

@@ -648,15 +648,20 @@ class Warnings(commands.Cog):
msg = "" msg = ""
guild_settings = await self.config.guild(ctx.guild).all() guild_settings = await self.config.guild(ctx.guild).all()
member_settings = self.config.member(user) member_settings = self.config.member(user)
async with member_settings.warnings() as user_warnings: user_warnings = await member_settings.warnings()
if not user_warnings.keys(): # no warnings for the user if not user_warnings: # no warnings for the user
if guild_settings["mywarnings_in_dms"]: if guild_settings["mywarnings_in_dms"]:
await ctx.tick() try:
await user.send(_("You have no warnings!")) await user.send(_("You have no warnings!"))
except discord.Forbidden:
await ctx.send(_("I could not send you a DM. Do you have DMs disabled?"))
else:
await ctx.tick()
else: else:
await ctx.send(_("You have no warnings!")) await ctx.send(_("You have no warnings!"))
else: return
for key in user_warnings.keys():
for key in user_warnings:
mod_id = user_warnings[key]["mod"] mod_id = user_warnings[key]["mod"]
if mod_id == 0xDE1: if mod_id == 0xDE1:
mod = _("Deleted Moderator") mod = _("Deleted Moderator")
@@ -671,23 +676,20 @@ class Warnings(commands.Cog):
) )
if mod is not None: if mod is not None:
msg += _(" issued by {user}").format(user=mod) msg += _(" issued by {user}").format(user=mod)
msg += _(" for {description} \n").format( msg += _(" for {description}\n").format(description=user_warnings[key]["description"])
description=user_warnings[key]["description"]
)
if guild_settings["mywarnings_in_dms"]: if guild_settings["mywarnings_in_dms"]:
if user.dm_channel is None:
await user.create_dm()
try: try:
await ctx.bot.send_interactive( await ctx.bot.send_interactive(
channel=user.dm_channel, channel=user,
messages=pagify(msg, shorten_by=58), messages=pagify(msg, shorten_by=58),
user=user, user=user,
box_lang=_("Warnings for {user}").format(user=user), box_lang=_("Warnings for {user}").format(user=user),
) )
await ctx.tick()
except discord.Forbidden: except discord.Forbidden:
await ctx.send(_("I could not send you a DM. Do you have DMs disabled?")) await ctx.send(_("I could not send you a DM. Do you have DMs disabled?"))
else:
await ctx.tick()
else: else:
await ctx.send_interactive( await ctx.send_interactive(