Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hi there,
The error message you’re seeing is aiohttp.client_exceptions.ClientOSError: [Errno 104] Connection reset by peer. This is a low-level networking error indicating that the other side (in this case, Discord’s servers) unexpectedly closed the connection.
The fact that this error occurs when running on your DigitalOcean droplet but not your local system is interesting. It suggests that the issue might be related to the droplet’s environment or network, rather than the bot’s code itself. Here are a few things to consider:
Rate Limiting: Discord has strict rate limits. If you exceed them, Discord might start dropping your connections. Make sure your bot respects Discord’s rate limits. You could be hitting these rate limits on the droplet but not your local machine due to differences in network latency or timing.
Network Issues: There could be transient network issues between your droplet and Discord’s servers. You could try running a network diagnostic tool like mtr to check for packet loss or high latency. Also, make sure your droplet’s firewall (if any) isn’t blocking or interfering with outbound connections.
Resource Limits: If your droplet is running low on resources (like memory or disk space), it could cause your bot to behave unpredictably. Check your droplet’s resource usage to ensure it has enough resources.
Python and Library Versions: Ensure that the Python version and the versions of the discord.py and aiohttp libraries are the same on both your local system and the droplet.
Concurrency Issues: If your bot is handling multiple requests concurrently, it could be running into concurrency issues. These issues can be hard to reproduce and might only occur under certain conditions (like when running on your droplet).
File System Differences: Your bot is creating and sending a file (ancient.png). There might be differences between your local file system and your droplet’s file system that are causing issues. For example, there might be permissions issues on the droplet that prevent your bot from creating or reading the file.
As a first step, I would recommend adding more logging to your bot to help pinpoint where the error is occurring. You could also try catching and handling the ClientOSError in your bot’s code to see if you can recover from the error or log additional information.
Best,
Bobby
Adjust aiohttp Timeout Settings
Since you’re using aiohttp, try increasing the timeout settings for the requests. You can do this by adjusting the ClientSession timeout in your bot code. For example:
from aiohttp import ClientTimeout
timeout = ClientTimeout(total=60) # Increase the timeout to 60 seconds
client = discord.Client(session=aiohttp.ClientSession(timeout=timeout))
Check Bot Version and aiohttp Version
discord.py and aiohttp versions are up to date on both your local machine and the droplet. Differences in versions might cause inconsistencies in behavior.