How to add spaces in async function discord.py

Viewed 95

I am making a discord chat bot. I want to set command "How are You?" But my program only choose 'How' . I need some suggestions.TIA

import discord
from discord.ext import commands
client = commands.Bot(command_prefix= '=')

@client.event
async def on_ready():
    print('Bot is online')
@client.command()
async def hello(ctx):
    await ctx.send('hello')
@client.command()
async def how_are_you(ctx):
    await ctx.send('I am good')
client.run('token')
1 Answers

If you want to use a command, i don't think you can register one with spaces in it, however there are a couple of workarounds:

First you can use the first word of your string as the command name and then check for the content of the message:

@client.command()
async def how(ctx):
    if ctx.message.content.lower() == "=how are you":
        await ctx.send("I'm fine thanks")
    else:
        pass

The = prefix is needed in the message, replace it when you want to change your prefix.

Or, the second option would be to set up an on_message listener.

@client.event
async def on_message(message):
    if message.content.lower().startswith("=how are you"):
        await message.channel.send("I'm fine thanks.")
    await client.process_commands(message)

Related