Replit Discord Bot Keeps Disconnecting

Hello, I’m relatively new to coding, so I hope you can assist me.

Overview
I’ve delved into creating a Discord bot for enjoyment, even with minimal coding experience and no budget for expensive servers or software. I opted to use Replit to develop my bot, which essentially responds to commands by sending an embed. I have implemented a command handler to manage this functionality.

Issue
The challenge I am encountering is that the bot frequently goes offline. Initially, it would remain active for several hours, but after recent tests, it now disconnects within approximately 20 minutes. There are no error messages; I simply find the bot offline when checking Replit and need to restart it.

Investigation
I searched for solutions online, but most suggestions involved acquiring a server and connecting it to uptimerobot or implementing keepAlive(), which I have set up from the start. I have monitored uptimerobot, and there have been no disconnections in the last two weeks.

To troubleshoot further, I developed a simpler Discord bot with only a ping function, which has remained online for over three days without issue. This leads me to believe the problem may stem from the bot’s many commands (105 in total), possibly overwhelming the basic resources offered by Replit. Furthermore, no users have engaged with the bot during its downtime.

I’d appreciate any guidance you could provide.
Thank you!

hey, have you checked your code for memory leaks? also, replit might have variable limits in their free tier, maybe consider using some dummy commands to see if reducing them mitigates the issue. or try logging steps to track where it’s failing.

I’ve faced similar issues with Discord bots on Replit. From my experience, one aspect worth investigating is the event loop. If tasks in your code are not yielding to the event loop properly, it could cause the bot to become temporarily unresponsive, leading to disconnections. You might want to ensure asynchronous functions are optimized, especially with the number of commands you’re handling. Also, consider checking the Discord.py library version, as updating it may resolve any unstability that could lead to frequent disconnections.

hey there! besides all the solid advice here, maybe try checking if you’re getting rate limited by discord itself? their API can throttle if too many requests are sent. also, disabling any unnecessary console logs might help reduce replit workloads. hope you get it sorted soon!

I’ve worked with Discord bots on Replit before, and one thing that comes to mind is the possibility of exceeding resource limits. Since Replit’s free tier has constraints on CPU and RAM usage, handling a substantial number of commands might be causing spikes in resource demand. When these limits are reached, your bot might get paused, which appears as a disconnection. You could try splitting your commands into different files or modules to manage resources better. Testing with a scaled-down version of your bot on the free plan might help identify if it’s a resource-related issue.