replit 上的令牌不正确
Improper token on replit
嗨,我一直收到错误消息
discord.errors.LoginFailure: Improper token has been passed.
这是我的代码
import discord
import os
client = discord.Client()
token = os.environ['token']
async def on_ready():
await client.change_presence(game=discord.Game(name=" dm for support ;)"))
client.run("token")
这是完整的错误信息
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 293, in static_login
data = await self.request(Route('GET', '/users/@me'))
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 247, 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 "main.py", line 11, in <module>
client.run("token")
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 718, in run
return future.result()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 697, in runner
await self.start(*args, **kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 660, in start
await self.login(*args, bot=bot)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 509, in login
await self.http.static_login(token.strip(), bot=bot)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 297, in static_login
raise LoginFailure('Improper token has been passed.') from exc
discord.errors.LoginFailure: Improper token has been passed.
最后这是令牌的屏幕截图
image of token in replit secrets
any help??
我认为有两件事是原因:
- 在这部分代码中
token = os.environ['token']
您正在检索一个名为 'token'
的环境变量,您应该在 运行 您的程序之前设置它。如果您还没有,那很容易做到:
Windows:
SET token=<value of token>
Linux 基于 OS:
export token=<value of token>
通过这种方式,您确保设置了此环境变量。
第二题:
在这部分代码中
client.run("token")
您没有使用之前用 token = os.environ['token']
提取的这个变量,而是实际上使用字符串 token
作为您的标记,我想这不是您的标记。这可以修复,如下所示:
client.run(token)
请注意,在本例中,我使用的是之前声明的变量 token
,而不是字符串 "token"
。
另外,这个 可能会有帮助。
嗨,我一直收到错误消息
discord.errors.LoginFailure: Improper token has been passed.
这是我的代码
import discord
import os
client = discord.Client()
token = os.environ['token']
async def on_ready():
await client.change_presence(game=discord.Game(name=" dm for support ;)"))
client.run("token")
这是完整的错误信息
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 293, in static_login
data = await self.request(Route('GET', '/users/@me'))
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 247, 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 "main.py", line 11, in <module>
client.run("token")
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 718, in run
return future.result()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 697, in runner
await self.start(*args, **kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 660, in start
await self.login(*args, bot=bot)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 509, in login
await self.http.static_login(token.strip(), bot=bot)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 297, in static_login
raise LoginFailure('Improper token has been passed.') from exc
discord.errors.LoginFailure: Improper token has been passed.
最后这是令牌的屏幕截图 image of token in replit secrets
any help??
我认为有两件事是原因:
- 在这部分代码中
token = os.environ['token']
您正在检索一个名为 'token'
的环境变量,您应该在 运行 您的程序之前设置它。如果您还没有,那很容易做到:
Windows:
SET token=<value of token>
Linux 基于 OS:
export token=<value of token>
通过这种方式,您确保设置了此环境变量。
第二题:
在这部分代码中
client.run("token")
您没有使用之前用 token = os.environ['token']
提取的这个变量,而是实际上使用字符串 token
作为您的标记,我想这不是您的标记。这可以修复,如下所示:
client.run(token)
请注意,在本例中,我使用的是之前声明的变量 token
,而不是字符串 "token"
。
另外,这个