Async def on_message(message):

my code:

import discord
import os

client = discord.Client()

@client.event
async def on_ready():
  print('We have logged in as {0.user}'
  .format(client)
@client.event
async def on_message(message):
  if message.author == client.user:
    return

    if message.conetnt.startswith('A!Hello'):
      await message.channel.send('Hi Sussy!')

      client.run(os.getenv('TOKEN'))

Also this is for a discord bot. I got this from freecodecamp.org

You have a spelling mistake in your code. It should be “content” and not “conetnt”. Also next time it’s better to give small description of the issue you are facing so it gives us an idea of what to look for.

Hey there! Thanks that will help with late errors but my promblem is
image

What is your python version? The syntax looks correct to me, I think it’s something to do with python.

Syntax error doesn’t necessarily is detected at the same line where the syntax error exists. Take a closer look at the brackets in lines

  print('We have logged in as {0.user}'
  .format(client)
2 Likes

Good catch, I totally missed that out. I had been thinking maybe his python version dint support aysnc.

Well you see thats the problem. I don’t know what version it is. I am using repl.it so maybe you can check or tell me how to because I have no clue.

Edit: I just checked and it is python 3.8.2

Well actually I have just found out that what sanity said was the problem and I did that but now it comes up with nothing instead of saying: We have logged in as Amog Craft BOT#8086

also this is the new code (I just added the my_secret = os.environ[‘TOKEN’])

import discord
import os

client = discord.Client()

@client.event
async def on_ready():
  print('We have logged in as {0.user}'
  .format(client))
  
@client.event
async def on_msg(message):  
  if message.author == client.user:
    return

    if message.content.startswith('A!Hello'):
      await message.channel.send('Hi Sussy!')

      client.run(os.getenv('TOKEN'))
my_secret = os.environ['TOKEN']

indentation is really important in python
all the stuff after the return is not executed because it is inside the first if statement and a return stops a function from executing

you need to fix your indentation

Hi there!
Sorry to be a pain but I do not really understand. Could youput it in more context please.

with the indentation like this, this statement is inside this if statement

meaning it will never be executed as you need that last line to connect to discord, but the if statement is inside a piece of code that execute when the script gets input from discord


if you don’t understand how python syntax works I suggest you study it before attempting something like this

Same my man thats annoying

If you have a question open your own topic