From d90e45f9e0188cfeaef914a78eda5f397730a47a Mon Sep 17 00:00:00 2001 From: PredaaA <46051820+PredaaA@users.noreply.github.com> Date: Sat, 3 Jul 2021 21:58:56 +0200 Subject: [PATCH] [Trivia] Handle potential Discord errors in session. --- redbot/cogs/trivia/session.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/redbot/cogs/trivia/session.py b/redbot/cogs/trivia/session.py index 45d177da8..2494e809a 100644 --- a/redbot/cogs/trivia/session.py +++ b/redbot/cogs/trivia/session.py @@ -1,5 +1,6 @@ """Module to manage trivia sessions.""" import asyncio +import contextlib import time import random from collections import Counter @@ -207,7 +208,8 @@ class TriviaSession: ) except asyncio.TimeoutError: if time.time() - self._last_response >= timeout: - await self.ctx.send(_("Guys...? Well, I guess I'll stop then.")) + with contextlib.suppress(discord.HTTPException): + await self.ctx.send(_("Guys...? Well, I guess I'll stop then.")) self.stop() return False if self.settings["reveal_answer"]: @@ -220,11 +222,19 @@ class TriviaSession: if self.settings["bot_plays"]: reply += _(" **+1** for me!") self.scores[self.ctx.guild.me] += 1 - await self.ctx.send(reply) + try: + await self.ctx.send(reply) + except (discord.NotFound, discord.Forbidden): + self.stop() + return False else: self.scores[message.author] += 1 reply = _("You got it {user}! **+1** to you!").format(user=message.author.display_name) - await self.ctx.send(reply) + try: + await self.ctx.send(reply) + except (discord.NotFound, discord.Forbidden): + self.stop() + return False return True def check_answer(self, answers):