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)
os.getenv()
. Alternatively and less secure you can add the token directly withoutos.getenv()
. – Klaus D.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