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()
@client.event
async def on_ready():
print('Hello.'.format(client))
@client.event
async def on_message(message):
if message.authoror == client.user:
return
if message.content.startswith('/hello'):
await message.channel.send('hello')
my_secret = os.environ['Key']
client.run(os.getenv('Key'))
here is all the code, and yes that is the turtorial im using
ilenia
July 25, 2021, 6:41pm
4
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.
system
Closed
January 24, 2022, 7:12am
6
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.