From d9db03bca3ee437f133f7fe3a8a7fd5028d18efb Mon Sep 17 00:00:00 2001 From: jack1142 <6032823+jack1142@users.noreply.github.com> Date: Thu, 19 Mar 2020 08:23:07 +0100 Subject: [PATCH] Tell the command caller when bot was unable to send warn (#3653) --- redbot/cogs/warnings/warnings.py | 34 +++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/redbot/cogs/warnings/warnings.py b/redbot/cogs/warnings/warnings.py index d9079f451..ceb31c956 100644 --- a/redbot/cogs/warnings/warnings.py +++ b/redbot/cogs/warnings/warnings.py @@ -361,19 +361,30 @@ class Warnings(commands.Cog): await warning_points_add_check(self.config, ctx, user, current_point_count) dm = await self.config.guild(ctx.guild).toggle_dm() + dm_failed = False if dm: em = discord.Embed( title=_("Warning from {user}").format(user=ctx.author), description=reason_type["description"], ) em.add_field(name=_("Points"), value=str(reason_type["points"])) - with contextlib.suppress(discord.HTTPException): + try: await user.send( _("You have received a warning in {guild_name}.").format( guild_name=ctx.guild.name ), embed=em, ) + except discord.HTTPException: + dm_failed = True + + if dm_failed: + await ctx.send( + _( + "A warning for {user} has been issued," + " but I wasn't able to send them a warn message." + ).format(user=user.mention) + ) toggle_channel = await self.config.guild(guild).toggle_channel() if toggle_channel: @@ -384,17 +395,22 @@ class Warnings(commands.Cog): em.add_field(name=_("Points"), value=str(reason_type["points"])) warn_channel = self.bot.get_channel(await self.config.guild(guild).warn_channel()) if warn_channel: - channel = warn_channel - await ctx.tick() - else: - channel = ctx.channel - if channel.permissions_for(guild.me).send_messages: - with contextlib.suppress(discord.HTTPException): - await channel.send( + if channel.permissions_for(guild.me).send_messages: + with contextlib.suppress(discord.HTTPException): + await channel.send( + _("{user} has been warned.").format(user=user.mention), embed=em, + ) + + if not dm_failed: + if warn_channel: + await ctx.tick() + else: + await ctx.send( _("{user} has been warned.").format(user=user.mention), embed=em ) else: - await ctx.tick() + if not dm_failed: + await ctx.tick() try: reason_msg = _( "{reason}\n\nUse `{prefix}unwarn {user} {message}` to remove this warning."