所以我试图在Heroku上运行这个非常简单的不和谐bot(https://github.com/RapidKebab/hibot420),在本地可以通过cmd运行它,并且可以使用dotenv和.env文件完美运行。
对于Heroku,它不会加载dotenv,因此git版本中已注释掉dotenv内容,并替换为应该从Heroku配置vars中拉出“ DISCORD_TOKEN”的东西,我确定令牌本身是正确的,但是我得到了错误“ 401:未经授权”和“ LoginFailure:令牌传递不正确。”显然,后者直接由前者引起。
日志:
2019-10-24T16:14:37.910317+00:00 heroku[worker.1]: Process exited with status 1
2019-10-24T16:14:37.959627+00:00 heroku[worker.1]: State changed from up to crashed
2019-10-24T16:14:37.77383+00:00 app[worker.1]: Traceback (most recent call last):
2019-10-24T16:14:37.773868+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/http.py", line 256, in static_login
2019-10-24T16:14:37.774648+00:00 app[worker.1]: data = await self.request(Route('GET', '/users/@me'))
2019-10-24T16:14:37.774654+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/http.py", line 220, in request
2019-10-24T16:14:37.775561+00:00 app[worker.1]: raise HTTPException(r, data)
2019-10-24T16:14:37.775615+00:00 app[worker.1]: discord.errors.HTTPException: 401 UNAUTHORIZED (error code: 0): 401: Unauthorized
2019-10-24T16:14:37.77562+00:00 app[worker.1]:
2019-10-24T16:14:37.775622+00:00 app[worker.1]: The above exception was the direct cause of the following exception:
2019-10-24T16:14:37.775623+00:00 app[worker.1]:
2019-10-24T16:14:37.775626+00:00 app[worker.1]: Traceback (most recent call last):
2019-10-24T16:14:37.775649+00:00 app[worker.1]: File "bot.py", line 27, in <module>
2019-10-24T16:14:37.77648+00:00 app[worker.1]: client.run(token)
2019-10-24T16:14:37.776484+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/client.py", line 640, in run
2019-10-24T16:14:37.778024+00:00 app[worker.1]: return future.result()
2019-10-24T16:14:37.778029+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/client.py", line 621, in runner
2019-10-24T16:14:37.778666+00:00 app[worker.1]: await self.start(*args, **kwargs)
2019-10-24T16:14:37.77902+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/client.py", line 584, in start
2019-10-24T16:14:37.780225+00:00 app[worker.1]: await self.login(*args, bot=bot)
2019-10-24T16:14:37.780246+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/client.py", line 442, in login
2019-10-24T16:14:37.782041+00:00 app[worker.1]: await self.http.static_login(token.strip(), bot=bot)
2019-10-24T16:14:37.782047+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/http.py", line 260, in static_login
2019-10-24T16:14:37.782977+00:00 app[worker.1]: raise LoginFailure('Improper token has been passed.') from exc
2019-10-24T16:14:37.783003+00:00 app[worker.1]: discord.errors.LoginFailure: Improper token has been passed.
答案 0 :(得分:1)
当我尝试使用heroku托管我的机器人时,遇到了相同的问题,我一次又一次地验证了我的代码,但是该机器人仍然无法正常工作。我的错误是在env vars中,我将令牌放在引号之间(因为它是一个字符串),但是heroku使用““ your token”“作为令牌,所以我尝试将不带引号的令牌放入var容器中,并且有效。也许您面临另一个问题,在这种情况下,请显示有关您的代码,heroku设置等的更多信息...