Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bot only takes one command

I'm trying to make a bot where when you type for example "!say hello world" and the bot would reply with "Hello World". But when I try to do spaces it doesn't work.

So when I simply type "!say Hello" it shows this:

As you can see it works fine but when I put a space for example "!say hello world" it shows this:

As you can see it only prints "Hello" and acts like I didn't say "World".

Here is my code:

@client.command()
async def say(ctx, arg):
    await ctx.send(arg)
like image 533
Flexes Avatar asked Jul 12 '20 18:07

Flexes


People also ask

Why can't I use bot commands in Discord?

The issue is because you are only running the client , not the bot . You need to also run the bot instance if you want it to function.

How do you give a bot a command?

To use a Discord bot command, simply type it into the text box on a text channel and press “enter”. The bot will prompt you for any follow-up Discord commands. See the GIF above for a quick example of how to use the “status” command on the IdleRPG bot.

Can Discord bots use commands?

Slash Commands are the new, exciting way to build and interact with bots on Discord. With Slash Commands, all you have to do is type / and you're ready to use your favorite bot. You can easily see all the commands a bot has, and validation and error handling help you get the command right the first time.


1 Answers

See here: Commands

Since positional arguments are just regular Python arguments, you can have as many as you want:

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

Sometimes you want users to pass in an undetermined number of parameters. The library supports this similar to how variable list parameters are done in Python:

@bot.command()
async def test(ctx, *args):
    await ctx.send('{} arguments: {}'.format(len(args), ', '.join(args)))
like image 89
Jonas Avatar answered Sep 29 '22 22:09

Jonas