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)
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.
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.
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.
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)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With