Skip to content

Commit

Permalink
[Trivia] Handle FileNotFoundError when adding a custom trivia list (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
leetfin authored Feb 3, 2023
1 parent d0f22a7 commit e0c335e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions redbot/cogs/trivia/trivia.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,8 +690,18 @@ async def _save_trivia_list(
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(
Expand Down

0 comments on commit e0c335e

Please sign in to comment.