Skip to content

Commit

Permalink
Error Handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoz committed May 24, 2024
1 parent 3bcde73 commit 1c12cc6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
3 changes: 3 additions & 0 deletions cogs/statustracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ async def update_status(self):
type=nextcord.ActivityType.watching, name=status_message
)
)
except ConnectionResetError:
print("Connection was reset. Retrying in 30 seconds...")
await asyncio.sleep(30)
except Exception as e:
print(f"Error updating status: {e}")
await asyncio.sleep(60)
Expand Down
20 changes: 12 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,21 @@ async def on_ready():

# Error Handling
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandNotFound):
await ctx.send("This command does not exist.")
async def on_application_command_error(interaction, error):
if isinstance(error, nextcord.NotFound):
await interaction.response.send_message("Interaction expired or not found.", ephemeral=True)
elif isinstance(error, nextcord.HTTPException):
await interaction.response.send_message("HTTP error occurred.", ephemeral=True)
elif isinstance(error, nextcord.Forbidden):
await interaction.response.send_message("You do not have permission to perform this action.", ephemeral=True)
elif isinstance(error, commands.CommandOnCooldown):
await interaction.response.send_message(f"Command is on cooldown. Please wait {error.retry_after:.2f} seconds.", ephemeral=True)
elif isinstance(error, commands.MissingPermissions):
await ctx.send("You don't have the required permissions to use this command.")
await interaction.response.send_message("You are missing required permissions.", ephemeral=True)
elif isinstance(error, commands.MissingRequiredArgument):
await ctx.send("You are missing a required argument.")
elif isinstance(error, commands.CommandOnCooldown):
await ctx.send("This command is on cooldown. Please try again later.")
await interaction.response.send_message("Missing a required argument.", ephemeral=True)
else:
await ctx.send(f"An error occured: {error}")
await interaction.response.send_message(f"An error occurred: {str(error)}", ephemeral=True)

@bot.command()
async def ping(ctx):
Expand Down

0 comments on commit 1c12cc6

Please sign in to comment.