1

So, I have a Python program using discord.py where I am trying to have functions manage different message commands, but when I put the "await" in the function, it gives me a syntax error because it's not in the async. Any way I can get around this?

def selectedCommand(message):
    await client.send_message(stuff in here)

@client.event
async def on_message(message):
    selectedCommand(message)

@client.event
async def on_edit_message(message):
    selectedCommand(message)

1 Answer 1

1

You need to make selectedCommand a coroutine (an async def function) as well, and then await it when it's called:

async def selectedCommand(message):
    await client.send_message(stuff in here)

@client.event
async def on_message(message):
    await selectedCommand(message)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.