From 218140c7b0d369980a20a3112bc0d250e3b0d5c7 Mon Sep 17 00:00:00 2001 From: Red-GitHubBot <88117545+Red-GitHubBot@users.noreply.github.com> Date: Thu, 20 Apr 2023 00:12:40 +0200 Subject: [PATCH] [3.4] [Trivia] Handle FileNotFoundError when adding a custom trivia list (#5950) (#6067) Co-authored-by: Leet <36166244+leetfin@users.noreply.github.com> --- redbot/cogs/trivia/trivia.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/redbot/cogs/trivia/trivia.py b/redbot/cogs/trivia/trivia.py index ffac72196..df9f6c01d 100644 --- a/redbot/cogs/trivia/trivia.py +++ b/redbot/cogs/trivia/trivia.py @@ -689,8 +689,18 @@ class Trivia(commands.Cog): TRIVIA_LIST_SCHEMA.validate(trivia_dict) buffer.seek(0) - with file.open("wb") as fp: - fp.write(buffer.read()) + try: + with file.open("wb") as fp: + fp.write(buffer.read()) + except FileNotFoundError as e: + await ctx.send( + _( + "There was an error saving the file.\n" + "Please check the filename and try again, as it could be longer than your system supports." + ) + ) + return + await ctx.send(_("Saved Trivia list as {filename}.").format(filename=filename)) def _get_trivia_session(self, channel: discord.TextChannel) -> TriviaSession: