我收到“discord.errors.HTTPException:401 Unauthorized(错误代码:0):401:Unauthorized”。到目前为止没有任何效果
2022-01-13
7189
这是我已经尝试过的:
-
尝试运行几个月未动过的代码,但出现同样的错误
-
我尝试重新生成令牌
-
我尝试了不同的机器人
-
我尝试了来自不同 discord 帐户的机器人
-
我尝试打印令牌,一切正常
-
我尝试将我的机器人更改为公开,并进行了一大堆其他 discord 机器人设置
-
我尝试了导入令牌的不同方法,例如,
Token = "Token" Client.run(Token)
还有一大堆不同的方法
-
尝试从 Visual Studio 更改为普通的 Python 终端
它刚刚突然发生这种情况,我正在编辑我的新机器人,运行了几次以从代码中清除错误,然后它工作了,然后关闭它再次运行它,它开始给我这个,所以我觉得这很奇怪,因为它太出乎意料了。我已经尝试了很多它在网上说的方法,但似乎都没有用。请帮忙,这已经持续了 4 天了,我希望它能被修复,因为这样我才能恢复机器人开发。
这是我得到的巨大错误:
Traceback (most recent call last):
File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\discord\http.py", line 349, in static_login
data = await self.request(Route('GET', '/users/@me'))
File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\discord\http.py", line 302, 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 "f:\Programming\Python\Discord bot\LastOneEverythingCombined\TEST.py", line 112, in <module>
client.run('OTA0NjMxMzE2MzU0NTg4NzEz.YX-VkQ._B-EnQRE3IhWYl0psJA8UxZuI6s')
File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\discord\client.py", line 631, in run
return future.result()
File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\discord\client.py", line 610, in runner
await self.start(*args, **kwargs)
File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\discord\client.py", line 573, in start
await self.login(*args)
File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\discord\client.py", line 424, in login
await self.http.static_login(token.strip())
File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\discord\http.py", line 353, 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 0x000001B4F30E1EA0>
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 116, in __del__
self.close()
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 108, in close
self._loop.call_soon(self._call_connection_lost, None)
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 745, in call_soon
self._check_closed()
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 510, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001B4F30E1EA0>
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 116, in __del__
self.close()
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 108, in close
self._loop.call_soon(self._call_connection_lost, None)
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 745, in call_soon
self._check_closed()
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 510, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001B4F30E1EA0>
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 116, in __del__
self.close()
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 108, in close
self._loop.call_soon(self._call_connection_lost, None)
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 745, in call_soon
self._check_closed()
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 510, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
我不知道如何修复它,并尝试了网络上的所有方法。这是我的代码:在 Token 的位置我有我的令牌,但当然让我们将它隐藏起来:)
client = commands.Bot(command_prefix='.')
Code....
client.run('Token')
上次我把我的整个代码放在那里,人们很生气,所以我现在只放了我认为可能对这个问题必要的代码,如果你需要任何其他代码,只需回复我需要所有的代码来解决这个错误或更多的代码,然后是你需要或认为可能在其中的特定位
2个回答
如果您使用 .env 保存令牌,请检查是否未将其放在括号中
它看起来像这样
MyBotToken=iBUGUgUVUIByViBiuvYiUBiyViBiV
(它不是实际的令牌,它只是一个例子)
SwirX
2022-04-05
我也遇到了同样的问题,我只是不断重置机器人令牌并使用它。 但这并没有解决问题。
后来我记得我在 Windows PC 中创建了一个环境变量,这导致了问题,更改它解决了我的问题。
Lucifer7535
2024-01-17