How would I make my .env file work in my .py file?

Making a discord bot and I want to store variables in a .env file.

It throws this exception:

  File "", line 24, in <module>
  File "", line 723, in run
    return future.result()
  File "", line 702, in runner
    await self.start(*args, **kwargs)
  File "", line 665, in start
    await self.login(*args, bot=bot)
  File "", line 511, in login
    await self.http.static_login(token.strip(), bot=bot)
AttributeError: 'NoneType' object has no attribute 'strip'

Before I moved the variables to the .env file it worked fine.
import os

from dotenv import load_dotenv
import discord

TOKEN = os.getenv("DISCORD_TOKEN")
GUILD = os.getenv("GUILD_NAME")

client = discord.Client()

async def on_ready():
    for guild in client.guilds:
        if == GUILD:

        f"{client.user} is connected to the following guild:n"
        f"{}(id: {}"


My .env and .py are in the same folder.


python-dotenv‘s load_env() searches for a .env file in the same directory as where it’s being executed.
If you change your .env filename to a custom one, like var.env, you must specify the filename: load_env("var.env")