Search code examples
pythondiscord

discord.py multiple arguments?


how do I have multiple args in one command in discord.py?

for example user: /say string bot: string

or user: /repeat integer bot: (repeats something a number of times)

or user: /kill @mention bot: user killed @mention

and is there a way where you can put them all into one command?


Solution

  • I believe this code should solve your problem:

    import discord
    from discord.ext import commands
    
    bot = commands.Bot(command_prefix='/')
    
    @bot.command()
    async def say(ctx, string: str):
        await ctx.send(string)
    
    @bot.command()
    async def repeat(ctx, integer: int):
        for i in range(integer):
            await ctx.send("Repeating something")
    
    @bot.command()
    async def kill(ctx, mention: discord.Member):
        await ctx.send("user killed {}".format(mention))