I’m experiencing the following error while trying to execute my Discord bot:
TypeError: expected token to be a str, received NoneType instead
Here’s the complete traceback of the error:
Traceback (most recent call last):
File "d:\Python\Projects\discord_bot\main", line 20, in <module>
client.run(os.getenv('BOT_TOKEN'))
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 828, in run
asyncio.run(executor())
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 817, in executor
await self.start(token, reconnect=reconnect)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 745, in start
await self.login(token)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 577, in login
raise TypeError(f'expected token to be a str, received {token.__class__.__name__} instead')
Here’s my code snippet:
import discord
import os
options = discord.Intents.default()
options.typing = False
options.presences = False
bot = discord.Client(intents=options)
@bot.event
async def on_ready():
print('Logged in as {0.user}'.format(bot))
@bot.event
async def on_message(msg):
if msg.author == bot.user:
return
if msg.content.startswith('$greet'):
await msg.channel.send('Greetings!')
bot.run(os.getenv('BOT_TOKEN'))
I don’t have any other files associated with this code; it’s the only one in the project folder. How can I resolve this error? Thank you! I’ve checked various solutions but haven’t found anything that fixes the issue.