Pycord-Development / pycord

Pycord is a modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python
https://docs.pycord.dev
MIT License
2.74k stars 462 forks source link

Constant Shard Reconnection and ConnectionClosed Errors with AutoShardedBot #2427

Closed MrMetacomCode closed 6 months ago

MrMetacomCode commented 6 months ago

Summary

I'm using commands.AutoShardedBot and I get these error messages periodically. Nothing in the error is my code and the only thing I have done to shard the bot is to change commands.Bot to commands.AutoShardedBot as seen below in the minimal reproducible code.

2024-04-17 22:56:21,545:ERROR:discord.shard: Attempting a reconnect for shard ID 1 in 0.76s
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/discord/shard.py", line 180, in worker
    await self.ws.poll_event()
  File "/usr/local/lib/python3.10/site-packages/discord/gateway.py", line 632, in poll_event
    raise ConnectionClosed(
discord.errors.ConnectionClosed: Shard ID 1 WebSocket closed with 1000
2024-04-17 23:14:59,106:ERROR:discord.shard: Attempting a reconnect for shard ID 2 in 0.67s
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/discord/shard.py", line 180, in worker
    await self.ws.poll_event()
  File "/usr/local/lib/python3.10/site-packages/discord/gateway.py", line 632, in poll_event
    raise ConnectionClosed(
discord.errors.ConnectionClosed: Shard ID 2 WebSocket closed with 1000

Reproduction Steps

Start a commands.AutoShardedBot instance and let it run.

Minimal Reproducible Code

import discord
from discord import Intents
from discord.ext import commands

intents = Intents(guild_messages=True, guilds=True, voice_states=True, messages=True, message_content=True, members=True,
                  reactions=True, auto_moderation_execution=True)
bot = commands.AutoShardedBot(intents=intents)

TOKEN = 123456
bot.run(TOKEN)

Expected Results

To not have constant shard reconnection/closed connection errors.

Actual Results

I'm getting the errors shown.

Intents

Shown in minimum reproducible code answer.

System Information

Docker Compose Container on Ubuntu Server Python 3.10 Pip Packages:

APScheduler==3.9.1
git+https://github.com/Pycord-Development/pycord.git
GitPython==3.1.42
PyYAML==6.0.1
python-dateutil==2.8.2
aiohttp==3.9.3
rsa==4.9

Checklist

Additional Context

No response

JustaSqu1d commented 6 months ago

I was unable to reproduce this