1
votes

I am developing a Discord Bot using Python. And getting the following error (AttributeError: 'NoneType' object has no attribute 'strip'). Here is my code.

import os
import discord
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('O.......')
GUILD = os.getenv('CodeUP')

client = discord.Client()

@client.event
async def on_ready():
    for guild in client.guilds:
        if guild.name == GUILD:
            break

    print(
        f'{client.user} is connected to the following guild:\n'
        f'{guild.name}(id: {guild.id})'
    )

client.run(TOKEN)
2
Can you post the full error traceback? - mousetail
If you print the TOKEN variable, you'll see it's None. The ODMyMTUxN.. key doesn't exist, I think that might be your actual token - Łukasz Kwieciński

2 Answers

1
votes

The thing you're supposed to get as the "token" is the variable name of your bot token stored in the .env file, like this!

Contents of .env file:

BOT_TOKEN=ODMyMTUxNjQ4OTAxMjY3NTA2.YHfnnQ.r_rQ2mmo8HFvaBAl9rry28VM4Nk

Token variable in the python file:

TOKEN = os.getenv('BOT_TOKEN')
0
votes

os.getenv gets a enviroment variable with the given name. You are using your token as your name. Replace the code with this:

TOKEN = os.getenv('DISCORD_TOKEN', 'ODMyMTUxNjQ4OTAxMjY3NTA2.YHfnnQ.r_rQ2mmo8HFvaBAl9rry28VM4Nk')

This find an environment variable named DISCORD_TOKEN, and if none exists, use 'ODM...'

I hope this is not your real token you are posting on the internet though, if so make sure to cancel it immediately.