diff options
| author | 2019-01-30 20:13:38 +0100 | |
|---|---|---|
| committer | 2019-01-30 20:13:38 +0100 | |
| commit | 7318071da2d9e90e08b5edfe6f245b8adc4ce37a (patch) | |
| tree | aaf2da4391bd33d8f676a713a81d96203d2494d8 | |
| parent | Merge pull request #294 from python-discord/redirect-free-command (diff) | |
| parent | Suppressing NotFound exception when trying to delete messages (diff) | |
Merge pull request #296 from python-discord/redirect-decorator-handling-deleted-msgs
Suppressing NotFound exception when trying to delete messages
| -rw-r--r-- | bot/decorators.py | 12 |
1 files 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 |