Discord Bot Python Connection Error: WinError 10054 Remote Host Forcibly Closed Connection

I built a Discord bot using Python that handles voting systems and external poll creation. After running for some time, I consistently encounter this connection error:

ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

Here’s my bot code:

import discord
from discord.ext import commands
import strawpoll
import asyncio

desc = '''Bot for creating voting systems and external polls'''

client = commands.Bot(command_prefix='!')

@client.event
async def on_ready():
    print('Bot is online')
    print(client.user.name)
    print(client.user.id)
    print('--------')

# Simple reaction voting
@client.command(name="vote", pass_context=True)
async def vote(ctx):
        await client.add_reaction(ctx.message, '✅')
        await client.add_reaction(ctx.message, '❌')
        await client.add_reaction(ctx.message, '❓')

# External poll with two options
@client.command(name="makepoll", pass_context=True)
async def makepoll(ctx):
    poll_api = strawpoll.API()
    await client.say('Enter poll title:')
    poll_title = await client.wait_for_message(author=ctx.message.author)
    await client.say('Enter first option:')
    option_a = await client.wait_for_message(author=ctx.message.author)
    await client.say('Enter second option:')
    option_b = await client.wait_for_message(author=ctx.message.author)
    new_poll = strawpoll.Poll(poll_title.content, [option_a.content, option_b.content])
    print(new_poll.id)                
    print(new_poll.url)               

    new_poll = await poll_api.submit_poll(new_poll)
    print(new_poll.id)                
    print(new_poll.url)

    await client.say(new_poll.url)

I’ve researched this error but haven’t found clear solutions. Even asking in Discord development communities didn’t provide definitive answers. Has anyone experienced similar connection issues with Discord bots?

yeah, this happens all the time on windows. discord’s api randomly drops connections and crashes your bot when it can’t handle the lost socket connection. add some retry logic or use pm2 to auto-restart when it dies. also check if your internet’s stable - sketchy wifi triggers this constantly.

This happens when Discord’s gateway connection drops unexpectedly. I’ve run into the same thing with bots that stay online for days without proper connection handling. Your code’s using the old discord.py version - client.say() and wait_for_message() are deprecated. Upgrade to discord.py 2.0+ and you’ll fix a lot of connection issues since it handles reconnections way better. The real problem is your bot doesn’t handle disconnections gracefully. Add on_disconnect() and on_resumed() handlers to see when these drops happen. Also throw in a heartbeat check - Discord expects regular pings and kills stale connections. That strawpoll integration might be adding extra strain during API calls too.

I’ve hit this exact error before - it’s usually rate limiting or connection issues. Discord kills the connection when your bot hammers their API too fast. Your makepoll command is probably the culprit since it fires off multiple messages back-to-back with no delays. Throw in some asyncio.sleep(0.5) between your client.say() calls. You’ll also want proper exception handling around API calls and reconnection logic. If you’re on a VPS or shared hosting, check if your IP got temporarily blocked from other users’ stuff. The strawpoll API might be timing out too, so wrap those calls in try-catch blocks.