From 899183f26d2904e7970acbb43c2ef3e4f4ca8f80 Mon Sep 17 00:00:00 2001 From: Ske Date: Sat, 27 Oct 2018 23:34:50 +0200 Subject: [PATCH] Fix special case where webhook is deleted by user --- src/pluralkit/bot/proxy.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/pluralkit/bot/proxy.py b/src/pluralkit/bot/proxy.py index 8997a948..a025f99d 100644 --- a/src/pluralkit/bot/proxy.py +++ b/src/pluralkit/bot/proxy.py @@ -103,13 +103,21 @@ async def do_proxy_message(conn, original_message: discord.Message, proxy_member inner_text: str, logger: ChannelLogger): # Send the message through the webhook webhook = await get_or_create_webhook_for_channel(conn, original_message.channel) - sent_message = await webhook.send( - content=inner_text, - username=proxy_member.name, - avatar_url=proxy_member.avatar_url, - file=await make_attachment_file(original_message), - wait=True - ) + + try: + sent_message = await webhook.send( + content=inner_text, + username=proxy_member.name, + avatar_url=proxy_member.avatar_url, + file=await make_attachment_file(original_message), + wait=True + ) + except discord.NotFound: + # The webhook we got from the DB doesn't actually exist + # If we delete it from the DB then call the function again, it'll re-create one for us + await db.delete_webhook(conn, original_message.channel.id) + await do_proxy_message(conn, original_message, proxy_member, inner_text, logger) + return # Save the proxied message in the database await db.add_message(conn, sent_message.id, original_message.channel.id, proxy_member.id,