[英]Traceback errors on python script within the discord\client.py error?
I am unable to run any python code within Visual Studio Code for discord correctly.我无法在 Visual Studio Code 中正确运行任何 python 代码以进行不一致。 The error message is persistent, and regardless of what method I use to access the file, the error keeps returning.
错误消息是持久的,无论我使用什么方法访问文件,错误都会不断返回。 the code is as follows:
代码如下:
def read_token():
path = '/path/used/to.txt'
with open(path, "r") as f:
lines = f.read()
return lines[0].strip()
token = read_token()
print(token)
try:
bot.run(token)
except discord.errors.LoginFailure as e:
print('login failed, ERROR 401 unauthorized')
doing this will output this on the terminal:这样做将在终端上输出:
<function read_token at 0x7f2d0edba268>
login failed, ERROR 401 unauthorized
The error gives this information :该错误提供了以下信息:
File "/home/falwaeth/.local/lib/python3.6/site-packages/discord/http.py", line 256, in static_login
data = await self.request(Route('GET', '/users/@me'))
File "/home/falwaeth/.local/lib/python3.6/site-packages/discord/http.py", line 220, 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 "/home/falwaeth/BotDev/bot.py", line 32, in <module>
bot.run(f'{token}')
File "/home/falwaeth/.local/lib/python3.6/site-packages/discord/client.py", line 640, in run
return future.result()
File "/home/falwaeth/.local/lib/python3.6/site-packages/discord/client.py", line 621, in runner
await self.start(*args, **kwargs)
File "/home/falwaeth/.local/lib/python3.6/site-packages/discord/client.py", line 584, in start
await self.login(*args, bot=bot)
File "/home/falwaeth/.local/lib/python3.6/site-packages/discord/client.py", line 442, in login
await self.http.static_login(token.strip(), bot=bot)
File "/home/falwaeth/.local/lib/python3.6/site-packages/discord/http.py", line 260, in static_login
raise LoginFailure('Improper token has been passed.') from exc
discord.errors.LoginFailure: Improper token has been passed.
What I do not understand is the improper token.我不明白的是不正确的令牌。 If I change the bot.run() to have the actual token in it, it will work.
如果我更改 bot.run() 以在其中包含实际令牌,它将起作用。 The permission of the .txt file is set to be able to be read by everyone.
.txt 文件的权限设置为所有人都可以读取。 Any ideas?
有任何想法吗?
The bot.run() will only work if the token is inside, i don't think i was meant to read from a .txt file in python. bot.run() 仅在令牌在内部时才有效,我不认为我打算从 python 中的 .txt 文件中读取。 I've changed some things on this working directory, it now runs python3.7.5.
我改变了这个工作目录的一些东西,它现在运行 python3.7.5。 I found another issue upon entering this code:
输入此代码后,我发现了另一个问题:
path = '/path/used/to.txt'
with open(path,'r') as f:
lines = f.readlines()
return lines[0].strip()
token = read_token
bot.run(token)
gives me this as an error now:现在给我这个错误:
File "/home/falwaeth/BotDev/welcomeBot.py", line 31, in <module>
bot.run(token)
File "/home/falwaeth/.local/lib/python3.7/site-packages/discord/client.py", line 640, in run
return future.result()
File "/home/falwaeth/.local/lib/python3.7/site-packages/discord/client.py", line 621, in runner
await self.start(*args, **kwargs)
File "/home/falwaeth/.local/lib/python3.7/site-packages/discord/client.py", line 584, in start
await self.login(*args, bot=bot)
File "/home/falwaeth/.local/lib/python3.7/site-packages/discord/client.py", line 442, in login
await self.http.static_login(token.strip(), bot=bot)
AttributeError: 'function' object has no attribute 'strip'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
Original exception was:
Traceback (most recent call last):
File "/home/falwaeth/BotDev/welcomeBot.py", line 31, in <module>
bot.run(token)
File "/home/falwaeth/.local/lib/python3.7/site-packages/discord/client.py", line 640, in run
return future.result()
File "/home/falwaeth/.local/lib/python3.7/site-packages/discord/client.py", line 621, in runner
await self.start(*args, **kwargs)
File "/home/falwaeth/.local/lib/python3.7/site-packages/discord/client.py", line 584, in start
await self.login(*args, bot=bot)
File "/home/falwaeth/.local/lib/python3.7/site-packages/discord/client.py", line 442, in login
await self.http.static_login(token.strip(), bot=bot)
AttributeError: 'function' object has no attribute 'strip'
any idea why?知道为什么吗?
f.read()
will return the contents of the file as a string, so lines[0].strip()
will be the first character of that file. f.read()
将以字符串形式返回文件的内容,因此lines[0].strip()
将是该文件的第一个字符。 I suspect you want this instead:我怀疑你想要这个:
path = '/path/used/to.txt'
with open(path, "r") as f:
lines = f.readlines()
return lines[0].strip()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.