Help with Discord Bot tutorial

import discord
import os

client = discord.Client()

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

async def on_message(message):
  if == client.user:

  if message.content.startswith('$hello'):

Error Msg

Traceback (most recent call last):
  File "", line 18, in <module>'Key'))
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/", line 723, in run
    return future.result()
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/", line 702, in runner
    await self.start(*args, **kwargs)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/", line 665, in start
    await self.login(*args, bot=bot)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/", line 511, in login
    await self.http.static_login(token.strip(), bot=bot)
AttributeError: 'NoneType' object has no attribute 'strip'```

I think this is an issue with how the environment is set up.
Most probably the os.getenv() method isn’t able to fetch the environment variable.
If your .env file is set up correctly, maybe you can consider using python-dotenv package to load the file.
Here’s an example of how to use it-

import os
from dotenv import load_dotenv


KEY = os.getenv('Key')

You can install the package using-
pip install python-dotenv

Also, I have a small suggestion(this is nothing big nor does it change anything, however it does help in some form of consistency) - Try to define the environment variables in CAPS(upper case)

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.