diff options
Diffstat (limited to 'bot/exts/info/pypi.py')
| -rw-r--r-- | bot/exts/info/pypi.py | 15 | 
1 files changed, 12 insertions, 3 deletions
| diff --git a/bot/exts/info/pypi.py b/bot/exts/info/pypi.py index 2e42e7d6b..62498ce0b 100644 --- a/bot/exts/info/pypi.py +++ b/bot/exts/info/pypi.py @@ -2,13 +2,15 @@ import itertools  import logging  import random  import re +from contextlib import suppress -from discord import Embed +from discord import Embed, NotFound  from discord.ext.commands import Cog, Context, command  from discord.utils import escape_markdown  from bot.bot import Bot  from bot.constants import Colours, NEGATIVE_REPLIES, RedirectOutput +from bot.utils.messages import wait_for_deletion  URL = "https://pypi.org/pypi/{package}/json"  PYPI_ICON = "https://cdn.discordapp.com/emojis/766274397257334814.png" @@ -67,8 +69,15 @@ class PyPi(Cog):                      log.trace(f"Error when fetching PyPi package: {response.status}.")          if error: -            await ctx.send(embed=embed, delete_after=INVALID_INPUT_DELETE_DELAY) -            await ctx.message.delete(delay=INVALID_INPUT_DELETE_DELAY) +            error_message = await ctx.send(embed=embed) +            await wait_for_deletion(error_message, (ctx.author.id,), timeout=INVALID_INPUT_DELETE_DELAY) + +            # Make sure that we won't cause a ghost-ping by deleting the message +            if not (ctx.message.mentions or ctx.message.role_mentions): +                with suppress(NotFound): +                    await ctx.message.delete() +                    await error_message.delete() +          else:              await ctx.send(embed=embed) | 
