【发布时间】:2021-06-01 14:57:24
【问题描述】:
我是编码新手,我一直在尝试制作一个简单的不和谐机器人,作为一个实验,当我尝试在 PythonAnywhere 上运行它时,我不断得到这个。我在 repl.it 上没有这个问题。
Traceback (most recent call last):
File "/home/DELICTREAJay/somthingother/somoo.py", line 10, in <module>
client.run(os.getenv('TOKEN'))
File "/home/DELICTREAJay/.local/lib/python3.8/site-packages/discord/client.py", line 718, in run
return future.result()
File "/home/DELICTREAJay/.local/lib/python3.8/site-packages/discord/client.py", line 697, in runner
await self.start(*args, **kwargs)
File "/home/DELICTREAJay/.local/lib/python3.8/site-packages/discord/client.py", line 660, in start
await self.login(*args, bot=bot)
File "/home/DELICTREAJay/.local/lib/python3.8/site-packages/discord/client.py", line 509, in login
await self.http.static_login(token.strip(), bot=bot)
AttributeError: 'NoneType' object has no attribute 'strip'
这是我的代码
import discord
import os
client = discord.Client()
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
client.run(os.getenv('TOKEN'))
我在保存令牌的同一目录中有一个单独的 .env 文件
【问题讨论】:
-
PythonAnywhere 帮助页面上的文章描述了如何使用 .env 文件来设置环境变量。
标签: python discord.py pythonanywhere