Discord Bot Code Attribute Error

When I run this code:

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 message.author == client.user:

if message.content.startswith(’$hello’):
await message.channel.send(‘Hello!’)


I get the error message:

Traceback (most recent call last):
File “main.py”, line 18, in
File “/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py”, line 723, in run
return future.result()
File “/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py”, line 702, in runner
await self.start(*args, **kwargs)
File “/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py”, line 665, in start
await self.login(*args, bot=bot)
File “/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py”, line 511, in login
await self.http.static_login(token.strip(), bot=bot)
AttributeError: ‘NoneType’ object has no attribute ‘strip’

How do I fix this?


Sharing the solution (same error, same code) from StackOverflow from a while ago…

Hope that helped! :slight_smile:
Happy coding and welcome to the forum!

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