Discord BOT, NameError

I have a problem.

i have put in the code:
if message.content.startswith(’/hello’):
await message.channel.send(‘hello’)

and i get this error:
File “main.py”, line 15, in on_ready
if message.content.startswith(’/hello’):
NameError: name ‘message’ is not defined

i’ve checked over many times and i have the exact code as the youtube guy i’m watching

Post all your code and please also provide what tutorial you are following just so we are sure. I assume you are following this tutorial?

Did you provide the message parameter to the on_message function?

import discord
import os

client = discord.Client()

async def on_ready():

  async def on_message(message):
    if message.authoror == client.user:
   if message.content.startswith('/hello'):
    await message.channel.send('hello')

my_secret = os.environ['Key']

here is all the code, and yes that is the turtorial im using

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Check your indentation and spelling.

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