Skip to content

Commit 1367365

Browse files
authored
Merge pull request zeusops#8 from zeusops/discord-error-handling
Improve Discord error handling
2 parents c0f4531 + 52c66c5 commit 1367365

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/zeusops_bot/cogs/zeus_upload.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ async def zeus_upload(
5353
@commands.slash_command(name="zeus-set-mission")
5454
async def zeus_set_mission(self, ctx: discord.ApplicationContext, filename: str):
5555
"""Activate the given a mission file as a Zeus"""
56-
await ctx.respond(f"Setting mission to {filename=}")
57-
self.reforger_confgen.zeus_set_mission(filename)
56+
try:
57+
self.reforger_confgen.zeus_set_mission(filename)
58+
await ctx.respond(f"Setting mission to {filename=}")
59+
except ConfigFileNotFound:
60+
await ctx.respond(f"Error: could not find mission '{filename}'")
5861

5962
@commands.slash_command(name="zeus-list")
6063
async def zeus_list(self, ctx: discord.ApplicationContext):
@@ -75,3 +78,10 @@ async def current_mission(self, ctx: discord.ApplicationContext):
7578
)
7679
except ConfigFileNotFound as e:
7780
await ctx.respond(f"Could not find configured mission: {str(e)}")
81+
82+
@commands.Cog.listener()
83+
async def on_application_command_error(
84+
self, ctx: discord.ApplicationContext, error: discord.DiscordException
85+
):
86+
"""Handles application command errors that are not caught elsewhere"""
87+
await ctx.respond(f"Unhandled exception: {error}")

0 commit comments

Comments
 (0)