Python 如何使我的机器人检测到命令前缀后的消息?

Python 如何使我的机器人检测到命令前缀后的消息?,python,discord.py,Python,Discord.py,据我所知,discord.ext导入命令的工作原理如下: bot = commands.Bot(command_prefix='John') @bot.command async def help(ctx): ctx.send.message('help_message') commandlist = ['help','command1','command2','command3'] input = ['Hi','Hello','Sup','Hey'] @bot.even

据我所知,discord.ext导入命令的
工作原理如下:

bot = commands.Bot(command_prefix='John')


@bot.command
async def help(ctx):
      ctx.send.message('help_message')
commandlist = ['help','command1','command2','command3']

input = ['Hi','Hello','Sup','Hey'] 

@bot.event
async def on_message(message):
      if 'John' in message:
            if all(commandlist) not in message and input in message:
                 await message.channel.send('Hi!')
如果我发送约翰帮助,机器人将向频道发送“帮助信息”

但是,我还希望我的bot使用
async def on_message
检测消息,我希望它检测每条消息,检查其中是否有John,如果有John,检查消息的其余部分,如果它不是命令之一,并且它有特定的单词,我希望它发送一个预先分配的响应

我希望它是这样的:

bot = commands.Bot(command_prefix='John')


@bot.command
async def help(ctx):
      ctx.send.message('help_message')
commandlist = ['help','command1','command2','command3']

input = ['Hi','Hello','Sup','Hey'] 

@bot.event
async def on_message(message):
      if 'John' in message:
            if all(commandlist) not in message and input in message:
                 await message.channel.send('Hi!')
如果我说约翰帮助,机器人将发送帮助信息,如果我说你好约翰你好约翰,机器人将说你好


上面的代码类似于伪代码,因此可能会有很多错误。

您需要检查
on_消息中发送的字符串的第一个单词。
我将使用str.split()方法获取字符串的第一个单词,以检查它是否等于John

@bot.event()
async def on_message(message):
   x = message.split(' ', 1)[0]    # This splits the first word of the string
   x = "John":
   while True:
     try:
     if commandlist in message:
        await message.channel.send('Your string')    
         break
     else:
       if input in message:
         await message.channel.send('Other String')
          break

我希望这有助于满足您的需求

'和'替换'和'