1

It doesn't let me pass multiple arguments to my function. Python keeps thinking I'm still defining the first argument. The code:

async def find(ctx, user, parachannel):
    user = int(user)
    parachannel = int(parachannel)
    funchannel = bot.get_channel(parachannel)
    fun_guild = bot.get_guild(880108797820026881)
    memberuser = fun_guild.get_member(user)
    fun_calc = 0
    async for message in funchannel.history(limit=10):
        if message.author == memberuser:
            fun_calc = fun_calc + 1
    return fun_calc


gen_calc = find(user, 880123663318409277)
print(gen_calc)

Getting this error:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: find() missing 1 required positional argument: 'parachannel'

Full Traceback:

2021-09-16T11:40:52.403142+00:00 app[worker.1]: Ignoring exception in command analyze:
2021-09-16T11:40:52.404102+00:00 app[worker.1]: Traceback (most recent call last):
2021-09-16T11:40:52.404120+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/core .py", line 85, in wrapped
2021-09-16T11:40:52.404121+00:00 app[worker.1]:     ret = await coro(*args, **kwargs)
2021-09-16T11:40:52.404122+00:00 app[worker.1]:   File "main.py", line 132, in analyze
2021-09-16T11:40:52.404123+00:00 app[worker.1]:     gen_calc = find(user, 880123663318409277)
2021-09-16T11:40:52.404142+00:00 app[worker.1]: TypeError: find() missing 1 required positional argument: 'parachannel'
2021-09-16T11:40:52.404151+00:00 app[worker.1]: 
2021-09-16T11:40:52.404152+00:00 app[worker.1]: The above exception was the direct cause of the following exception:
2021-09-16T11:40:52.404152+00:00 app[worker.1]: 
2021-09-16T11:40:52.404154+00:00 app[worker.1]: Traceback (most recent call last):
2021-09-16T11:40:52.404170+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/bot.py", line 939, in invoke
2021-09-16T11:40:52.404170+00:00 app[worker.1]:     await ctx.command.invoke(ctx)
2021-09-16T11:40:52.404172+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/core.py", line 863, in invoke
2021-09-16T11:40:52.404173+00:00 app[worker.1]:     await injected(*ctx.args, **ctx.kwargs)
2021-09-16T11:40:52.404181+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/core.py", line 94, in wrapped
2021-09-16T11:40:52.404181+00:00 app[worker.1]:     raise CommandInvokeError(exc) from exc
2021-09-16T11:40:52.404195+00:00 app[worker.1]: discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: find() missing 1 required positional argument: 'parachannel'
4
  • 1
    Your function waits for 3 arguments. You call your function passing only 2 arguments. Commented Sep 16, 2021 at 11:52
  • Ctx isn't an argument, it's an object (I think) @Gustavo Araújo Commented Sep 16, 2021 at 11:57
  • just delete 'ctx' and test @Mushtaq Mahar Commented Sep 16, 2021 at 11:58
  • @MushtaqMahar ctx is quite literally a parameter for your function. It's only passed automatically for commands, not for regular methods. If you're calling the function yourself, either pass ctx as an argument or remove it. Commented Sep 16, 2021 at 13:32

3 Answers 3

0

Your function requires three arguments but you only pass two to it. So, naturally you see an error. You should give your parameters some default values. For example something like this:

async def find(ctx = None, user = "Mushtaq", parachannel = 0):
    user = int(user)
    parachannel = int(parachannel)
... and the rest of your code.
Sign up to request clarification or add additional context in comments.

1 Comment

If the username is a string by default then int(user) is gonna raise a ValueError though. I know this is an example but still.
0

find(ctx, user, parachannel) function requires 3 arguments: ctx, user and parachannel. But when you call the function you're only giving two arguments. ctx = user and user = 880123663318409277. You're missing the 3rd argument parachannel.

Comments

0

If it's not necessary to keep ctx as first argument, you can do

async def find(user, parachannel, ctx = None):
    # You codes
    return fun_calc

Now you can call your function without ctx argument.

gen_calc = find(user, 880123663318409277)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.