Unsure of await functionallity

Issue

I am using discordpy to write a discord bot. When calling an external function from an async function, I am receiving an error telling me I am missing a parameter ‘ctx’ from my function. I believe I have to use the ‘await’ method, however, I am unsure where.

def fromRebootMethod():
    return "Hello"

@client.command()
async def fromReboot(ctx):
    message = await fromRebootMethod()
    print(message)
    await ctx.send(message)

This is the error I am receiving:

TypeError: fromReboot() missing 1 required positional argument: ‘ctx’

Solution

I don’t think the provided code sample is completely accurate. Therefore, I am recommending two steps to potentially resolve your issue:

  1. Only use await when calling a function that is defined with the async keyword in the function definition.
  2. Take another look at the fromRebootMethod‘s function definition. It most likely requires a ctx parameter which is why your interpreter is asking for it.

Regardless, we need to see the traceback and real code sample.

Answered By – Joshua Taylor Eppinette

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published