Deno deploy running my code multiple times

Im hosting a small discord bot on deno deploy but for some reason its firing the events multiple times and everytime i save the project to shut it down and start it again it doubles. so in this case when i delete a message it first send one message telling me its deleted. then when i patched a bug it became 2 messages and now its 4. is there a way to fix this?
DAH
Deno AI Helper22d ago
It sounds like you're encountering an issue where your Discord bot's event handlers are being registered multiple times, which is why you're seeing the events firing multiple times. This can happen if your code is being re-executed without properly shutting down previous instances or if the event listeners are being added multiple times without being cleared. Here are a few steps you can take to debug and potentially resolve this issue: 1. Ensure Proper Shutdown: Make sure that when you're shutting down your bot, it properly deregisters any event listeners or cleans up resources. This can prevent old listeners from persisting and responding to events. 2. Singleton Pattern: If your bot is designed to run as a singleton, ensure that you have logic in place to prevent multiple instances of the bot from running simultaneously. This can be done by checking if an instance already exists before starting a new one. 3. Code Review: Review your code to ensure that you're not adding event listeners in a loop or in a way that could cause them to be registered multiple times. 4. Deno Deploy Behavior: According to the documentation, Deno Deploy guarantees at least once execution for cron tasks and queue messages. While this is not directly related to Discord bot events, it's important to design your application to handle the possibility of multiple invocations, which could be a similar concept to what you're experiencing with event handlers. 5. Check for Errors: Look for any errors in your code or logs that might indicate why multiple instances are being created or why event handlers are being registered multiple times. 6. Minimal Reproduction: Try to create a minimal version of your bot that only includes the event that's causing issues. This can help
DAH
Deno AI Helper22d ago
isolate the problem and make it easier to debug. 7. Deno Deploy Dashboard: Use the Deno Deploy dashboard to monitor your deployments and see if there are multiple active instances that could be causing the issue. If you've gone through these steps and the issue persists, it might be helpful to reach out to the Deno community on Discord for support, as they might have encountered similar issues or have specific insights into the behavior of Deno Deploy with Discord bots. 🦕
K
Kay22d ago
alrr how do i run my bot in a singleton patern then?