The first couple of hours works fine, but after that it starts to fail with the following error:
File "/usr/local/lib/python3.8/dist-packages/nextcord/gateway.py", line 629, in poll_event raise ConnectionClosed(self.socket, shard_id=self.shard_id, code=code) from None nextcord.errors.ConnectionClosed: Shard ID None WebSocket closed with 1000
I read on different forums, they write that it can be because of the parser
Tried to solve it for a week, even put handlers, still crashes the bot.
Parser accesses Discord API via token, receives new messages from a certain channel, and immediately sends them to another channel.
There is a main bot that receives requests from the user, and there is a parser that accesses the discord API and picks up messages, then they will be forwarded to the main bot.
@bot.event
async def on_ready():
# Thread(target=run_main).start()
print('Thread started.')
await bot.change_presence(
status=nextcord.Status.online,
activity=nextcord.Activity(type=nextcord.ActivityType.watching, name='Active Channels'))
logger.info(msg='Бот запущен!')
if __name__ == '__main__':
logging.basicConfig(level=logging.WARNING)
bot.add_cog(Sharer(bot))
bot.loop.create_task(main())
asyncio.run(bot.run(token))
async def main():
while True:
tasks = await TasksDAO.find_all()
for task in tasks:
messages = await getter.get_messages(task.token, task.id_from)
new_messages = await getter.filter_new_messages(task.last_message_id, messages)
if new_messages == 0: # Если нету last_message_id, обновляем
messages = await getter.get_messages(task.token, task.id_from)
await TasksDAO.change_last_message_id(messages[-1]['id'], task.id) # обновляем id последнего сообщения
elif new_messages:
list_messages = [{message['content']: message['id']} for message in messages]
new_list_messages = [{message['content']: message['id']} for message in new_messages]
print(list_messages)
print(new_list_messages)
await TasksDAO.change_last_message_id(new_messages[-1]['id'], task.id) # обновляем id последнего сообщения
bot.dispatch('resending', task.id_to, new_messages, task.token, task.use_link, task.use_embed)```
Алексей is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.