'await' outside function

hii, my replit is gimme an error

File “main.py”, line 16
await message.channel.send(‘hello!’)
^
SyntaxError: ‘await’ outside function

in python help me guys. the code is down.|

import discord
import os

client = discord.Client()

@client.event
async def on_ready():
print(‘Logged is as {0.user}’.format(client))

@client.event
async def on_message(message):
if message.author == client.user:
return

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

client.run(os.environ(‘TOKEN’))

This happens because you are not in a function calling that. You must indent the code so it is within an aysnc function

1 Like

What @bigminiboss said:

import discord
import os

client = discord.Client()

@client.event
async def on_ready():
    print('Logged is as {0.user}'.format(client))

@client.event
async def on_message(message):
    if message.author == client.user:
        return
    
    if message.content.startswith('$hello'):
        await message.channel.send('hello!')

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