我正在尝试制作一个不和谐的机器人,当我尝试使用 load_dotenv() 加载 .env 时,它不起作用,因为它说
Traceback (most recent call last):
File "/home/fanjin/Documents/Python Projects/Discord Bot/bot.py", line 15, in <module>
client.run(TOKEN)
File "/home/fanjin/.local/lib/python3.8/site-packages/discord/client.py", line 708, in run
return future.result()
File "/home/fanjin/.local/lib/python3.8/site-packages/discord/client.py", line 687, in runner
await self.start(*args, **kwargs)
File "/home/fanjin/.local/lib/python3.8/site-packages/discord/client.py", line 650, in start
await self.login(*args, bot=bot)
File "/home/fanjin/.local/lib/python3.8/site-packages/discord/client.py", line 499, in login
await self.http.static_login(token.strip(), bot=bot)
AttributeError: 'NoneType' object has no attribute 'strip
Run Code Online (Sandbox Code Playgroud)
这是我的机器人代码:
import os
import discord
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
client = discord.Client()
@client.event
async def …Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的不和谐机器人安装 dotenv,pip3 install dotenv但它一直给我这个错误:
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-xmobtpdk/dotenv/setup.py'"'"'; __file__='"'"'/tmp/pip-install-xmobtpdk/dotenv/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-xmobtpdk/dotenv/pip-egg-info
cwd: /tmp/pip-install-xmobtpdk/dotenv/
Complete output (51 lines):
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-wheel-ts7a2idz/distribute/setup.py'"'"'; __file__='"'"'/tmp/pip-wheel-ts7a2idz/distribute/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-vsx7w_h3
cwd: /tmp/pip-wheel-ts7a2idz/distribute/
Complete output (15 lines):
Traceback (most recent call last):
File "<string>", line …Run Code Online (Sandbox Code Playgroud)