如何在'on message'事件中使用wait_for命令重写discord.py

How to use wait_for command in the 'on message' event discord.py rewrite

我正在尝试让 discord 机器人具有与 input() 命令,但由于 discord.py rewrite 没有该命令,我搜索了 API 并找到了 wait_for。但是,当然,它带来了一大堆问题。我在互联网上搜索了这个,但大多数答案都在 @command.command 而不是 async def on_message(message) 中,而其他答案并没有太大帮助。我得到的最远的是:

def check(m):
    if m.author.name == message.author.name and m.channel.name == message.channel.name:
        return True
    else:
        return False
msg = "404 file not found"
try:
msg = await client.wait_for('message', check=check, timeout=60)
await message.channel.send(msg)
except TimeoutError:
    await message.channel.send("timed out. try again.")
    pass
except Exception as e:
    print(e)
    pass

    ```

首先,您对多个事物使用同一个变量 msg。这是我可以根据您提供的信息制作的一个工作示例。

msg = "404 file not found"
await message.channel.send(msg)

def check(m):
    return m.author == message.author and m.channel == message.channel

try:
    mesg = await client.wait_for("message", check=check, timeout=60)
except TimeoutError: # The only error this can raise is an asyncio.TimeoutError
    return await message.channel.send("Timed out, try again.")
await message.channel.send(mesg.content) # mesg.content is the response, do whatever you want with this

消息returns一个message对象。

希望对您有所帮助!