From 11b7eb2e1f948de4b196b918d291ad909b3d5467 Mon Sep 17 00:00:00 2001 From: Flame442 <34169552+Flame442@users.noreply.github.com> Date: Tue, 19 Nov 2019 18:03:50 -0500 Subject: [PATCH] Multiple changes (#81) Fixed an error when the press f message is deleted Fixed a bug where two press fs could be started and the second would error Fixed a bug where a message from any channel could be used as the thing to pay respects to --- pressf/pressf.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pressf/pressf.py b/pressf/pressf.py index a53606b..6c5643b 100644 --- a/pressf/pressf.py +++ b/pressf/pressf.py @@ -19,6 +19,7 @@ class PressF(commands.Cog): return await ctx.send( "Oops! I'm still paying respects in this channel, you'll have to wait until I'm done." ) + self.channels[str(ctx.channel.id)] = {} if user: answer = user.display_name @@ -26,11 +27,12 @@ class PressF(commands.Cog): await ctx.send("What do you want to pay respects to?") def check(m): - return m.author == ctx.author + return m.author == ctx.author and m.channel == ctx.channel try: pressf = await ctx.bot.wait_for("message", timeout=120.0, check=check) except asyncio.TimeoutError: + del self.channels[str(ctx.channel.id)] return await ctx.send("You took too long to reply.") answer = pressf.content[:1900] @@ -41,10 +43,13 @@ class PressF(commands.Cog): await message.add_reaction("\U0001f1eb") self.channels[str(ctx.channel.id)] = {'msg_id': message.id, 'reacted': []} await asyncio.sleep(120) - await message.delete() + try: + await message.delete() + except (discord.errors.NotFound, discord.errors.Forbidden): + pass amount = len(self.channels[str(ctx.channel.id)]['reacted']) word = "person has" if amount == 1 else "people have" - await ctx.channel.send(f"**{amount}** {word} paid respects to **{filter_mass_mentions(answer)}**.") + await ctx.send(f"**{amount}** {word} paid respects to **{filter_mass_mentions(answer)}**.") del self.channels[str(ctx.channel.id)] @commands.Cog.listener()