【问题标题】:Repl.it environment secret variables are None typeRepl.it 环境秘密变量是 None 类型
【发布时间】: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


【解决方案1】:

此 Traceback 显示“TK”变量为空。如果您实际上没有在 replit env 机密中添加一个机密,则可能会发生这种情况,如果是这样,请添加一个这样的:

replit preview

拥有 .env 文件不会帮助您解决问题,因为 repl 最近删除了对它们的支持。

【讨论】:

  • 我已经像这样正确添加了令牌,但它不起作用
【解决方案2】:

我所做的是重新创建了我的 repl,并确保您创建了一个 Python repl。

【讨论】:

    猜你喜欢
    • 2023-03-08
    • 2023-01-22
    • 2018-06-14
    • 2020-08-19
    • 1970-01-01
    • 2021-10-29
    • 2018-01-21
    • 2022-10-04
    • 2023-01-30
    相关资源
    最近更新 更多