【发布时间】:2021-10-09 06:30:38
【问题描述】:
我正在尝试制作一个不和谐的机器人。 在 repl.it 中使用秘密环境变量,当我尝试获取变量的值时,它说它是 None 类型
import discord
import os
client = discord.Client()
@client.event
async def onReady():
print('Yeah Bwoi I am here : {0.user}'.format(client))
@client.event
async def onMessage(message):
if message.author == client.user:
return
if message.content.startswith('$hello'):
await message.channel.send('Yeee')
TK=os.environ.get('TOKEN')
print(TK)
client.run(TK)
结果:
None
Traceback (most recent call last):
File "main.py", line 20, in <module>
client.run(TK)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 723, in run
return future.result()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 702, in runner
await self.start(*args, **kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 665, in start
await self.login(*args, bot=bot)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 511, in login
await self.http.static_login(token.strip(), bot=bot)
AttributeError: 'NoneType' object has no attribute 'strip'
【问题讨论】:
-
尝试打印令牌。
标签: python python-3.x discord discord.py repl.it