运行时错误:事件循环已关闭,当两个具有相同代码的机器人同时运行时

时间:2020-05-12 17:52:06

标签: python bots discord.py

我一直在使用discord.py制作机器人,但遇到了问题。我当时正在运行一个机器人,所以我决定制造另一个机器人。当我在新服务器上对其进行测试时,收到一条错误消息RuntimeError: Event loop is closed.,但其他机器人并没有发生这种情况,该机器人与第一个机器人具有完全相同的代码,只是令牌不同。为什么会发生这种情况,我应该怎么做才能解决?这是完整的错误消息:

Traceback (most recent call last):
  File "C:\Python38\lib\site-packages\discord\http.py", line 261, in static_login
    data = await self.request(Route('GET', '/users/@me'))
  File "C:\Python38\lib\site-packages\discord\http.py", line 225, in request
    raise HTTPException(r, data)
discord.errors.HTTPException: 401 Unauthorized (error code: 0): 401: Unauthorized

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\26afa\Documents\GameBotDiscord\GameBot3000.py", line 24, in <module>
    client.run(token)  # recall my token was saved!
  File "C:\Python38\lib\site-packages\discord\client.py", line 640, in run
    return future.result()
  File "C:\Python38\lib\site-packages\discord\client.py", line 621, in runner
    await self.start(*args, **kwargs)
  File "C:\Python38\lib\site-packages\discord\client.py", line 584, in start
    await self.login(*args, bot=bot)
  File "C:\Python38\lib\site-packages\discord\client.py", line 442, in login
    await self.http.static_login(token.strip(), bot=bot)
  File "C:\Python38\lib\site-packages\discord\http.py", line 265, in static_login
    raise LoginFailure('Improper token has been passed.') from exc
discord.errors.LoginFailure: Improper token has been passed.
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x0000019F1121F430>
Traceback (most recent call last):
  File "C:\Python38\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Python38\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Python38\lib\asyncio\base_events.py", line 719, in call_soon
    self._check_closed()
  File "C:\Python38\lib\asyncio\base_events.py", line 508, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

1 个答案:

答案 0 :(得分:1)

从错误消息的外观来看,它在抱怨该机器人的令牌。确保您在TokenBot标签中添加了developer's page,而不是客户ID。

此外,如果不确定或从其他文件中获取令牌,请确保将令牌打印出来并与开发人员页面上的令牌进行比较。

如果仍然无法使用,请生成一个新令牌并使用它。