0
votes

im going off a website (https://realpython.com/how-to-make-a-discord-bot-python/#how-to-make-a-discord-bot-in-python) and im following there steps but i keep getting an error msg

Traceback (most recent call last): File "C:\Users\Bryce.Persello346\Desktop\bot.py", line 15, in client.run(TOKEN) File "C:\Users\Bryce.Persello346\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 718, in run return future.result() File "C:\Users\Bryce.Persello346\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 697, in runner await self.start(*args, **kwargs) File "C:\Users\Bryce.Persello346\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 660, in start await self.login(*args, bot=bot) File "C:\Users\Bryce.Persello346\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 509, in login await self.http.static_login(token.strip(), bot=bot) AttributeError: 'NoneType' object has no attribute 'strip'

my code:


import os

import discord
from dotenv import load_dotenv

load_dotenv()
TOKEN = os.getenv('"token here"')

client = discord.Client()

@client.event
async def on_ready():
    print(f'{client.user} has connected to Discord!')

client.run(TOKEN)

1
This question might help.M-Chen-3
Make sure: a. The token is stored in an environment variable. b. the name of environment variable is the argument to os.getenv(). Alternatively and less secure you can add the token directly without os.getenv().Klaus D.
Try replacing os.getenv('"token here"') with your token (Ex: TOKEN = 'QWERTYUIOP...') to test if it's working, if it does, then you're not getting your key correctly from the .env file.Sujit
i did not put my token in the code for security before i published i swapped it outSenpaiSpaghetti

1 Answers

1
votes

In the example on real python you may have made the mistake of putting the key in curly braces. so basically just format your env file like this...

DISCORD_TOKEN = token_goes_here

instead of...

DISCORD_TOKEN = {token_goes_here}