Anyone know how to use .env?(

I'm trying to hide my token in a .env file so people can't get my bot's token, and I don't know how to get my token variable from the file.
TOKEN=da token(not telling u lol)
token = os.getenv("TOKEN")

I have a feeling that my code is wrong, but I don't know what the right code is.

You are viewing a single comment. View All
Answered by AloegelhiPlaysR [earned 5 cycles]
View Answer

@TristanMurphy Here, join the team I invited you to. I'll help ya out for a sec. You'll be surprised.


@AloegelhiPlaysR didnt get an invite


@AloegelhiPlaysR btw is there a chance that you know how I can run it 24/7 using uptimerobot? I already have it configured in the dashboard, but I paused it so I could fix this. I noticed that when I run it, I get an error after it says updating
Traceback (most recent call last):
File "", line 169, in <module>
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/", line 708, in run
return future.result()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/", line 687, in runner
await self.start(args, **kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/", line 650, in start
await self.login(
args, bot=bot)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/", line 499, in login
await self.http.static_login(token.strip(), bot=bot)
AttributeError: 'NoneType' object has no attribute 'strip'


lol nvm im an idiot and put DISCORD_BOT_TOKEN instead of DISCORD_BOT_SECRET which was in the variable lol