[3.4] [Trivia] Handle FileNotFoundError when adding a custom trivia list (#5950) (#6067)

Co-authored-by: Leet <36166244+leetfin@users.noreply.github.com>
This commit is contained in:
Red-GitHubBot
2023-04-20 00:12:40 +02:00
committed by GitHub
parent d252b71be7
commit 218140c7b0

View File

@@ -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: