From ead3f809c5a2b0be52ef5c547b8566d3c9aaf205 Mon Sep 17 00:00:00 2001 From: SebastiaanZ <33516116+SebastiaanZ@users.noreply.github.com> Date: Wed, 30 Jan 2019 19:38:08 +0100 Subject: Suppressing NotFound exception when trying to delete messages --- bot/decorators.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/bot/decorators.py b/bot/decorators.py index 0e372671a..1ba2cd59e 100644 --- a/bot/decorators.py +++ b/bot/decorators.py @@ -2,10 +2,12 @@ import logging import random import typing from asyncio import Lock, sleep +from contextlib import suppress from functools import wraps from weakref import WeakValueDictionary from discord import Colour, Embed +from discord.errors import NotFound from discord.ext import commands from discord.ext.commands import CheckFailure, Context @@ -134,7 +136,13 @@ def redirect_output(destination_channel: int, bypass_roles: typing.Container[int if RedirectOutput.delete_invocation: await sleep(RedirectOutput.delete_delay) - await message.delete() - await ctx.message.delete() + + with suppress(NotFound): + await message.delete() + log.trace("Redirect output: Deleted user redirection message") + + with suppress(NotFound): + await ctx.message.delete() + log.trace("Redirect output: Deleted invocation message") return inner return wrap -- cgit v1.2.3