# Steps on how to setup environment variable for FCC Python Bot Tutorial

**URL:** <https://forum.freecodecamp.org/t/steps-on-how-to-setup-environment-variable-for-fcc-python-bot-tutorial/473303>\
**Category:** Curriculum Help\
**Tags:** python\
**Created:** [August 11, 2021, 1:18am UTC](https://forum.freecodecamp.org/t/steps-on-how-to-setup-environment-variable-for-fcc-python-bot-tutorial/473303 "2021-08-11T01:18:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jwilkins.oboe](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jwilkins.oboe/32/179497_2.png) [@jwilkins.oboe](https://forum.freecodecamp.org/u/jwilkins.oboe)\
**Post date:** [August 11, 2021, 1:18am UTC](https://forum.freecodecamp.org/t/steps-on-how-to-setup-environment-variable-for-fcc-python-bot-tutorial/473303/1 "2021-08-11T01:18:15Z")

</div>

Read this post if you are watching the [Code a Discord Bot](https://www.youtube.com/watch?v=SPTfmiYiuok) tutorial by FCC and don’t know how to setup your environment variables in replit.

A few months ago, Replit changed how to add environment variables.  
The suggestions from the video will not work.

Here is what you do.

Use this starter code from [discord.py docs](https://discordpy.readthedocs.io/en/stable/quickstart.html)

This is the exact same code from the video.  
You can just copy it.

```auto
import discord

client = discord.Client()

@client.event
async def on_ready():
  print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
  if message.author == client.user:
    return

  if message.content.startswith('$hello'):
    await message.channel.send('Hello!')

client.run('your token here')

```

Now let’s setup the environment variables.

Step 1:  
Click the lock icon that says secrets

 ![click on secrets tab](https://global.discourse-cdn.com/freecodecamp/original/3X/0/f/0f659a34182d95ab4e464ead65fed25ecfc87ab3.png)

Step 2:  
Add your key and value to the secrets tab and click add new secret.  
My suggestion: Just use TOKEN for the key name.  
Keep it simple for now.

 ![key and value secrets tab](https://global.discourse-cdn.com/freecodecamp/original/3X/1/b/1b8da8b46ed7c82eb4521a15816efaae9a92e2bd.png)

Step 3:  
Click insert to add `import os` to the top of your file

 ![click import os](https://global.discourse-cdn.com/freecodecamp/original/3X/2/2/2250fde8248095123e8ef5202ca0df36f1b3a713.png)

Step 4:  
Click insert to add your environment variable to the bottom of your code

 ![insert your token](https://global.discourse-cdn.com/freecodecamp/original/3X/1/f/1fa97b69dd697ee3d386fd53ccbe2b7c905f76d1.png)

Now we are going to change this line `client.run('your token here')`

Step 5:  
Add the my\_secret variable to your client.run.

```auto
client.run(my_secret)

```

Here is the complete code to get your bot up and running.  
If you are successful then you should see this message in the console

```auto
import os
import discord

client = discord.Client()

@client.event
async def on_ready():
  print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
  if message.author == client.user:
    return

  if message.content.startswith('$hello'):
    await message.channel.send('Hello!')

my_secret = os.environ['TOKEN']
client.run(my_secret)

```

 ![success in running bot](https://global.discourse-cdn.com/freecodecamp/original/3X/4/b/4b6e8b8bdb6495ffc78008a351ebe99692d8dee9.png)

If you are still getting errors, make a new post in the forum and tell us what the error message is and provide your code/replit link.

Hopefully that will help some people. 😀

---

<div class="post-metadata">

**Author:** ![jwilkins.oboe](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jwilkins.oboe/32/179497_2.png) [@jwilkins.oboe](https://forum.freecodecamp.org/u/jwilkins.oboe)\
**Post date:** [August 11, 2021, 1:18am UTC](https://forum.freecodecamp.org/t/steps-on-how-to-setup-environment-variable-for-fcc-python-bot-tutorial/473303/2 "2021-08-11T01:18:30Z")

</div>

Closed on August 11, 2021, 1:18am UTC


