mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-12-06 09:22:31 -05:00
[Trivia] Handle potential Discord errors in session.
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user