Ask coding questions

← Back to all posts
'await' outside function error
abriani434 (2)

I've encountered a very frustrating delay. I'm using the python environment and I'm having an error saying "SyntaxError: 'await' outside function". Does anyone know how to fix this?

Comments
hotnewtop
abriani434 (2)

@Coder100 @InvisibleOne @VulcanWM thanks :) i'll try these and see if they work

abriani434 (2)

ok - well, the error doesn't show up anymore, but now the bot won't respond to the ay!newr and ay!delr commands. (newr stands for 'new roast' and delr stands for 'delete roast')

Does anyone have any fixes for this?


VulcanWM (3100)

That’s because you haven’t made a function for them @abriani434

abriani434 (2)

@VulcanWM oh i see .-. im very very new at this so uh i dont know that much - how do i make a function?

Coder100 (19280)

The reason why you have the error is because you unindented, so it was outside of an async function.

Coder100 (19280)

All await keywords must be in an async function, like this:

InvisibleOne (3264)

To use await, it needs to be inside of an asynchronous function, this will give you an error:

but this won't:

VulcanWM (3100)

When you make the function in which the await is in, define it as async def functionname() instead of def functionname()