Skip to content
await error
Profile icon
RmyDahGod

hi. i am trying to make a discord chat bot.
when i put in “await”
there is this error appearing : Syntax Error : ‘await’ outside function

You are viewing a single comment. View All
Answered by KHZ [earned 5 cycles]
View Answer
Profile icon
KHZ

@RmyDahGod
Btw your repl is private so we can't look at your code. If you don't want us to see the code try attaching a screenshot of the code where the error is so we can take a look at the error.

Profile icon
KHZ

@RmyDahGod
Yup the problem is that you are using await outside of an async function. The last two lines should be like this:

@client.event async def on_message(msg): if msg.author == client.user: return if msg.startswith('hello'): await ctx.send('yo, whats good.')

I also made some necessary changes. And you should put the token in a .env file so that even if the repl is public you don't need to remove the token to show it to someone.

Profile icon
RmyDahGod

@KHZ
ohh shoot i didn’t see, let me put it in public

Profile icon
RmyDahGod

@KHZ
ight, it’s in public.