如何在异步函数discord.py中添加空格



我正在制作一个不和谐的聊天机器人。我想设置命令"你好吗"但我的程序只选择"如何"。我需要一些建议。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')

如果你想使用一个命令,我认为你不能注册一个有空格的命令,但有几个解决办法:

首先,您可以使用字符串的第一个单词作为命令名,然后检查消息的内容:

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

消息中需要=前缀,如果要更改前缀,请将其替换。

或者,第二种选择是设置一个on_message侦听器。

@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)