(utils): Improve embed_reply and error_reply.

Added better error handling for message responses.
Changed the `embed_reply` colour.
This commit is contained in:
2021-09-13 09:10:38 +03:00
parent a9d5f8f0e1
commit a0cd2530c9

View File

@@ -7,13 +7,16 @@ from settings import GuildSettings, UserSettings
@Context.util @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. Simple helper to embed replies.
All arguments are passed to the embed constructor. All arguments are passed to the embed constructor.
`desc` is passed as the `description` kwarg. `desc` is passed as the `description` kwarg.
""" """
embed = discord.Embed(description=desc, colour=colour, **kwargs) embed = discord.Embed(description=desc, colour=colour, **kwargs)
try:
return await ctx.reply(embed=embed, reference=ctx.msg)
except discord.NotFound:
return await ctx.reply(embed=embed) return await ctx.reply(embed=embed)
@@ -27,12 +30,15 @@ async def error_reply(ctx, error_str, **kwargs):
colour=discord.Colour.red(), colour=discord.Colour.red(),
description=error_str description=error_str
) )
message = None
try: try:
message = await ctx.ch.send(embed=embed, reference=ctx.msg, **kwargs) message = await ctx.ch.send(embed=embed, reference=ctx.msg, **kwargs)
ctx.sent_messages.append(message) except discord.NotFound:
return message message = await ctx.ch.send(embed=embed, **kwargs)
except discord.Forbidden: except discord.Forbidden:
message = await ctx.reply(error_str) message = await ctx.reply(error_str)
finally:
if message:
ctx.sent_messages.append(message) ctx.sent_messages.append(message)
return message return message