-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Open
Labels
unconfirmed bugA bug report that needs triagingA bug report that needs triaging
Description
Summary
When closing the client object and creating a new one and connecting, the logger persists and repeats outputs. I'm guessing you need to remove the logger in or after client.close()?
Reproduction Steps
If you create a client instance, close it with await client.close(), reset the variables and the event handler, and run it again, the logger persists and repeats the connection message twice (logging in using a static token... etc.).
This is because it is attached to the module itself (_log = logging.getLogger(__name__) in gateway.py).
If you repeat this process 3 times you get 3 loggers and so on.
Minimal Reproducible Code
import discord
import asyncio
from time import sleep
intents = discord.Intents.default()
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print(f'Logged in as {client.user} (ID: {client.user.id})')
print('------')
sleep(1)
await client.close()
client.run(TOKEN)
sleep(2)
intents = discord.Intents.default()
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print(f'Logged in as {client.user} (ID: {client.user.id})')
print('------')
sleep(1)
await client.close()
client.run(TOKEN)Expected Results
2025-11-30 05:45:04 INFO discord.client logging in using static token
2025-11-30 05:45:05 INFO discord.gateway Shard ID None has connected to Gateway (Session ID: SESSION_ID_1).
Logged in as CLIENT_USER_OUTPUT (ID: ID_OUTPUT)
2025-11-30 05:45:10 INFO discord.client logging in using static token
2025-11-30 05:45:11 INFO discord.gateway Shard ID None has connected to Gateway (Session ID: SESSION_ID_2).
Logged in as CLIENT_USER_OUTPUT (ID: ID_OUTPUT)
Actual Results
2025-11-30 05:45:04 INFO discord.client logging in using static token
2025-11-30 05:45:05 INFO discord.gateway Shard ID None has connected to Gateway (Session ID: SESSION_ID_1).
Logged in as CLIENT_USER_OUTPUT (ID: ID_OUTPUT)
2025-11-30 05:45:10 INFO discord.client logging in using static token
2025-11-30 05:45:10 INFO discord.client logging in using static token
2025-11-30 05:45:11 INFO discord.gateway Shard ID None has connected to Gateway (Session ID: SESSION_ID_2).
2025-11-30 05:45:11 INFO discord.gateway Shard ID None has connected to Gateway (Session ID: SESSION_ID_2).
Logged in as CLIENT_USER_OUTPUT (ID: ID_OUTPUT)
Intents
discord.Intents.default()
System Information
- Python v3.13.5-final
- discord.py v2.6.4-final
- aiohttp v3.13.2
- system info: Windows 10 10.0.19045
Checklist
- I have searched the open issues for duplicates.
- I have shown the entire traceback, if possible.
- I have removed my token from display, if visible.
Additional Context
If it really is as simple as just closing the logger when closing the client I can do a PR maybe?
Metadata
Metadata
Assignees
Labels
unconfirmed bugA bug report that needs triagingA bug report that needs triaging