Skip to content
Sign upLog in
← Back to Community

'await' outside function error

Profile icon
abriani434

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?
Screen Shot 2021-06-30 at 11.57.27 PM


Screen Shot 2021-06-30 at 11.57.34 PM

Voters
Profile icon
itsbaginn27
Profile icon
abriani434
Comments
hotnewtop
Profile icon
abriani434

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

Profile icon
abriani434

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?

Invalid image url

Invalid image url

Profile icon
VulcanWM

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

@abriani434

Profile icon
abriani434

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

Profile icon
Coder100

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

Profile icon
Coder100

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

async def func(): await ...
Profile icon
InvisibleOne

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

def hello(message): await message.channel.send("Hello!")

but this won't:

async def hello(message): await message.channel.send("Hello!")
Profile icon
VulcanWM

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