Skip to content
Advertisement

discord.py – How can I have 2 arguments in a command?

just wondering how an I have 2 arguments, for example

User: ?text A B
Bot: A B

Like “arg1” and “arg2” Example:

await bot.say({} {}.format(arg1, arg2))

Advertisement

Answer

For 2 args as 2 separate variables you could do something like this

@bot.command()
async def args(ctx, arg1, arg2):
    await ctx.send('You sent {} and {}'.format(arg1, arg2))

Or if you want to send all args passed as a list you could do… as per the rewrite documentation:

@bot.command()
async def args(ctx, *args):
    await ctx.send('`{}` arguments: `{}`'.format(len(args), ', '.join(args)))

Or if you want to send everything as one argument you could do (documentation):

@bot.command()
async def args(ctx, *, arg):
    await ctx.send(arg)
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement