Код: Выделить всё
[2025-11-22 02:08:24] [INFO ] discord.client: Logging in using static token.
[2025-11-22 02:08:25] [INFO ] discord.http: Found user agent Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36, build number 471383.
[2025-11-22 02:08:25] [INFO ] discord.gateway: Connected to Gateway (Session ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx).
Ready
Closed
[2025-11-22 02:08:33] [INFO ] discord.client: Logging in using static token.
[2025-11-22 02:08:33] [INFO ] discord.client: Logging in using static token.
[2025-11-22 02:08:33] [INFO ] discord.http: Found user agent Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36, build number 471383.
[2025-11-22 02:08:33] [INFO ] discord.http: Found user agent Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36, build number 471383.
[2025-11-22 02:08:34] [INFO ] discord.gateway: Connected to Gateway (Session ID: yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy).
[2025-11-22 02:08:34] [INFO ] discord.gateway: Connected to Gateway (Session ID: yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy).
Ready
Closed
[2025-11-22 02:08:42] [INFO ] discord.client: Logging in using static token.
[2025-11-22 02:08:42] [INFO ] discord.client: Logging in using static token.
[2025-11-22 02:08:42] [INFO ] discord.client: Logging in using static token.
[2025-11-22 02:08:43] [INFO ] discord.http: Found user agent Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36, build number 471383.
[2025-11-22 02:08:43] [INFO ] discord.http: Found user agent Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36, build number 471383.
[2025-11-22 02:08:43] [INFO ] discord.http: Found user agent Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36, build number 471383.
[2025-11-22 02:08:43] [INFO ] discord.gateway: Connected to Gateway (Session ID: zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz).
[2025-11-22 02:08:43] [INFO ] discord.gateway: Connected to Gateway (Session ID: zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz).
[2025-11-22 02:08:43] [INFO ] discord.gateway: Connected to Gateway (Session ID: zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz).
Ready
Closed
Ниже приведен базовый код, который я написал, чтобы проверить эту ошибку и получить приведенные выше выходные данные. У меня установлены discord.py и discord.py-self.
Код: Выделить всё
import discord
from discord.ext import tasks
import threading
import time
USER_TOKEN = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
client = None
class BgThread(threading.Thread):
def run(self):
self.client = self.DiscordClient()
try:
self.client.run(USER_TOKEN) # blocking
except Exception as ex:
print('The DiscordClient errored.')
print(str(type(ex)))
print(str(ex))
print(str(traceback.format_exc()))
print('Closed')
class DiscordClient(discord.Client):
def __init__(self):
super().__init__()
self.shouldStop = False
async def on_ready(self):
print('Ready')
self.checkShouldStop.start()
@tasks.loop(seconds=1.0)
async def checkShouldStop(self):
if self.shouldStop:
await self.close()
if __name__ == '__main__':
while True:
# Make and run a new background thread.
bgThread = BgThread()
bgThread.start()
time.sleep(5)
# Stop the background thread.
bgThread.client.shouldStop = True
while (bgThread.is_alive()):
time.sleep(0.5)
time.sleep(3)
Подробнее здесь: https://stackoverflow.com/questions/798 ... -restarted
Мобильная версия