From a0cd2530c923824a5dde5aacbb57c1123ef33ff6 Mon Sep 17 00:00:00 2001 From: Conatum Date: Mon, 13 Sep 2021 09:10:38 +0300 Subject: [PATCH] (utils): Improve `embed_reply` and `error_reply`. Added better error handling for message responses. Changed the `embed_reply` colour. --- bot/utils/ctx_addons.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/bot/utils/ctx_addons.py b/bot/utils/ctx_addons.py index 5833961a..6dc3e0b9 100644 --- a/bot/utils/ctx_addons.py +++ b/bot/utils/ctx_addons.py @@ -7,14 +7,17 @@ from settings import GuildSettings, UserSettings @Context.util -async def embed_reply(ctx, desc, colour=discord.Colour(0x9b59b6), **kwargs): +async def embed_reply(ctx, desc, colour=discord.Colour.orange(), **kwargs): """ Simple helper to embed replies. All arguments are passed to the embed constructor. `desc` is passed as the `description` kwarg. """ embed = discord.Embed(description=desc, colour=colour, **kwargs) - return await ctx.reply(embed=embed) + try: + return await ctx.reply(embed=embed, reference=ctx.msg) + except discord.NotFound: + return await ctx.reply(embed=embed) @Context.util @@ -27,14 +30,17 @@ async def error_reply(ctx, error_str, **kwargs): colour=discord.Colour.red(), description=error_str ) + message = None try: message = await ctx.ch.send(embed=embed, reference=ctx.msg, **kwargs) - ctx.sent_messages.append(message) - return message + except discord.NotFound: + message = await ctx.ch.send(embed=embed, **kwargs) except discord.Forbidden: message = await ctx.reply(error_str) - ctx.sent_messages.append(message) - return message + finally: + if message: + ctx.sent_messages.append(message) + return message def context_property(func):