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?