Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python discord.py |检查两条或更多消息_Python_Discord.py - Fatal编程技术网

Python discord.py |检查两条或更多消息

Python discord.py |检查两条或更多消息,python,discord.py,Python,Discord.py,我试图编写一个discord机器人程序,一个接一个地检查多条消息。 因此,如果有人写“你好”,机器人应该写“你好”,并检查下面的消息“你好吗?”是否正确 但是bot忽略了第二个命令。为什么?您发送的第二条消息将再次作为消息传递给on_message()函数。 试试这个 当这样写的时候,它会检查邮件中是否有问候语。要使您的机器人响应,然后等待响应,请使用wait\u for 它看起来是这样的: @client.event async def on_message(message): if

我试图编写一个discord机器人程序,一个接一个地检查多条消息。 因此,如果有人写“你好”,机器人应该写“你好”,并检查下面的消息“你好吗?”是否正确


但是bot忽略了第二个命令。为什么?

您发送的第二条消息将再次作为消息传递给on_message()函数。 试试这个


当这样写的时候,它会检查邮件中是否有问候语。要使您的机器人响应,然后等待响应,请使用
wait\u for

它看起来是这样的:

@client.event
async def on_message(message):
    if 'hi' in message.content:
        await message.channel.send('Hello there.')
        await bot.wait_for("How are you", check=check)

这样做的目的是,如果消息中包含hi,则bot会做出响应,然后等待一条消息,提示您如何完成本文并帮助其他人。我将在此处发布正确且完成的代码

@client.event
async def on_message(message):
    if message.content.startswith('Hi'):
        channel = message.channel
        await channel.send('Hello!')

        def check(message1):
            return message1.content == 'How are you?' and message1.channel == channel

        msg = await client.wait_for('message', check=check)
        await channel.send("I am fine.".format(msg))

我希望这篇文章能帮助其他人!祝你今天愉快

机器人正在等待,但它无法回答“你好”这个问题。我该怎么做呢?在等待后的线上,你会写ctx.send(“伟大的hbu”)
@client.event
async def on_message(message):
    if 'hi' in message.content:
        await message.channel.send('Hello there.')
        await bot.wait_for("How are you", check=check)
@client.event
async def on_message(message):
    if message.content.startswith('Hi'):
        channel = message.channel
        await channel.send('Hello!')

        def check(message1):
            return message1.content == 'How are you?' and message1.channel == channel

        msg = await client.wait_for('message', check=check)
        await channel.send("I am fine.".format(msg))