TypeError: object dict can’t be used in ‘await’ expression

I encountered this error while coding a button for discord py bot.

You may experience this error with any other type, for example even string / str can’t be used in ‘await’ expression.

The issue is pretty simple.

Why do we get this can’t be used in await expression error

The error is triggered when we use await for a synchronous function. So the return of the function is added to the error and we are told that we can’t use it in await expression.

Solution

Solution is pretty simple, use it with async functions only or remove await (if possible).

So your code should be like this:

async function b():
  return true

# now use this in your other async function or a triggered event:
a = await b()

This will now work fine as we’re now calling async function with await in our python script.

Leave a Reply

Your email address will not be published.