Sahaj Bhatt
Sahaj Bhatt

Reputation: 25

Repl.it environment secret variables are None type

I am trying to make a discord bot. Using secret environment variables in repl.it, when I try to take the value of the variable, it says its of None type

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)

Result:

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'

Upvotes: 1

Views: 636

Answers (2)

zvz
zvz

Reputation: 193

What I did is I recreated my repl and make sure you create a Python repl.

Upvotes: 0

xGhostCat
xGhostCat

Reputation: 11

This Traceback shows that the "TK" variable is empty. This can happen if you haven't actually added a secret into the replit env secrets, if thats the case add one like this:

replit preview

Having a .env file won't help your case as repl recently remove support for them.

Upvotes: 1

Related Questions