Discord.py: 'await' outside function

Created on 23 Oct 2019  路  5Comments  路  Source: Rapptz/discord.py

i'm trying to make a bot go offline with a command
i use:
if "#go.away" in message.content.lower():
await client.close()

and get

SyntaxError: 'await' outside function

can anyone help?

off-topic question

All 5 comments

https://docs.python.org/3/library/asyncio-task.html
https://www.python.org/dev/peps/pep-0492/

This is not an issue with discord.py.
GitHub issues for this repository should be used to report issues with this library.
They are not a medium for requesting help with Python.
For further help specific to using this library, you should join either the official discord.py server or the Discord API server, as the README also links.

Is there any possibility of discord.py's functionality being accessed via synchronous functions? Dealing with Python's async implementation may be more painful than strictly necessary for some use cases. (E.g., I just need to log in and then send messages from another source, no need to react to Discord events at all.)

If you just want to send messages, use webhooks which have an async and a sync api.
If that still doesn't work, it's easy enough to make the requests to the API using requests or some other sync lib.

Discord.py is very fundamentally async because logging in and receiving events (which is really a primary goal of discord.py) simply cannot be sync. As mentioned prior, it's very easy to do everything except event handling yourself with a library like requests.

I take it there's some more setup required somewhere to use discord.Webhook? The documentation of the id parameter is non-informative.

discord.errors.NotFound: 404 NOT FOUND (error code: 10015): Unknown Webhook

This issue has been answered and your queries are unrelated to the original issue. If you need more help consider joining the official Discord server.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Be4Vision picture Be4Vision  路  3Comments

jzburda picture jzburda  路  3Comments

adhoc92 picture adhoc92  路  3Comments

danshat picture danshat  路  3Comments

AraHaan picture AraHaan  路  3Comments