aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2021-08-03 13:10:05 -0700
committerGravatar MarkKoz <[email protected]>2021-08-03 13:10:05 -0700
commit900bf69a3178e1cdacfd7492a359d53f3b7db72a (patch)
tree2d244b8c95ff5438419990f592495562b8b660f6
parentCodeSnippets: refactor snippet parsing into a separate function (diff)
CodeSnippets: don't send snippets if the original message was deleted
Fixes BOT-13B
-rw-r--r--bot/exts/info/code_snippets.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/bot/exts/info/code_snippets.py b/bot/exts/info/code_snippets.py
index 8c86b9a93..4a90a0668 100644
--- a/bot/exts/info/code_snippets.py
+++ b/bot/exts/info/code_snippets.py
@@ -4,8 +4,8 @@ import textwrap
from typing import Any
from urllib.parse import quote_plus
+import discord
from aiohttp import ClientResponseError
-from discord import Message
from discord.ext.commands import Cog
from bot.bot import Bot
@@ -240,7 +240,7 @@ class CodeSnippets(Cog):
return '\n'.join(map(lambda x: x[1], sorted(all_snippets)))
@Cog.listener()
- async def on_message(self, message: Message) -> None:
+ async def on_message(self, message: discord.Message) -> None:
"""Checks if the message has a snippet link, removes the embed, then sends the snippet contents."""
if message.author.bot:
return
@@ -249,7 +249,11 @@ class CodeSnippets(Cog):
destination = message.channel
if 0 < len(message_to_send) <= 2000 and message_to_send.count('\n') <= 15:
- await message.edit(suppress=True)
+ try:
+ await message.edit(suppress=True)
+ except discord.NotFound:
+ # Don't send snippets if the original message was deleted.
+ return
if len(message_to_send) > 1000 and message.channel.id != Channels.bot_commands:
# Redirects to #bot-commands if the snippet contents are too long