[Trivia] Handle potential Discord errors in session.

This commit is contained in:
PredaaA
2021-07-03 21:58:56 +02:00
parent 9d35df2048
commit d90e45f9e0

View File

@@ -1,5 +1,6 @@
"""Module to manage trivia sessions."""
import asyncio
import contextlib
import time
import random
from collections import Counter
@@ -207,6 +208,7 @@ class TriviaSession:
)
except asyncio.TimeoutError:
if time.time() - self._last_response >= timeout:
with contextlib.suppress(discord.HTTPException):
await self.ctx.send(_("Guys...? Well, I guess I'll stop then."))
self.stop()
return False
@@ -220,11 +222,19 @@ class TriviaSession:
if self.settings["bot_plays"]:
reply += _(" **+1** for me!")
self.scores[self.ctx.guild.me] += 1
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)
try:
await self.ctx.send(reply)
except (discord.NotFound, discord.Forbidden):
self.stop()
return False
return True
def check_answer(self, answers):