-2

So im trying to make a function that call other function like this

@command.command()
async def test1(self, ctx):
    text = "hi john"
    await test2(ctx, text)

@command.command()
async def test2(self, ctx, *, text):
    await ctx.send(text)

it will say

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: test2() takes 2 positional arguments but 3 were given

and if i tried

@command.command()
async def test1(self, ctx):
    text = "hi john"
    await test2(text)

@command.command()
async def test2(self, ctx, *, text):
    await ctx.send(text)

it will say

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: test11() missing 1 required keyword-only argument: 'num'

And if i remove the * from test2 so that it become

@command.command()
async def test1(self, ctx):
    text = "hi john"
    await test2(ctx, text)

@command.command()
async def test2(self, ctx, text):
    await ctx.send(text)

then it will work perfectly fine.

Note: i need * arg on test2 so that when i type test2, it can receive input more than 1 word. But the problem appears when i use other function to call test2. Please help

Huskclaw
  • 1
  • 2
  • Does this answer your question? [Bare asterisk in function arguments?](https://stackoverflow.com/questions/14301967/bare-asterisk-in-function-arguments) – TheFungusAmongUs Jul 13 '22 at 04:20

1 Answers1

0

You're looking for the invoke() method.

@command.command()
async def test1(self, ctx):
    text = "hi john"
    await ctx.invoke(self.bot.get_command('test2'), text=text)

@command.command()
async def test2(self, ctx, *, text):
    await ctx.send(text)

For the first parameter of invoke(), you specify which command you want to call, and all subsequent parameters are used to specify the arguments of that command.

Aditya Tomar
  • 1,601
  • 2
  • 6
  • 25