且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

discord.py-机器人不响应多个连接的消息

更新时间:2023-11-19 11:29:34

您可以使用 wait_for_message 具有 check 函数,以等待来自具有特定内容的某些用户的消息:

You can use wait_for_message with a check function to wait for messages from certain users with certain content:

elif type.lower() == "kk":
    await bot.send_message(ctx.message.channel, "Knock Knock.")

    check = lambda m: "who's there" in m.content.lower()
    await bot.wait_for_message(author=ctx.message.author, channel=ctx.message.channel, check=check)
    kk = [["A little old lady", "All this time, I did not know you could yodel."],
          ["Cow says", "Cow says mooooo!"],
          ["Etch", "Bless you, friend."],
          ["Robin", "Now hand over the cash."],
          ["Cash", "No thanks, I'll have some peanuts."],
          ["Mustache", "I mustache you a question, but I'll shave it for later."],
          ["Tank", "You're welcome."],
          ["Candice", "Candice door open, or what?"],
          ["Boo", "No need to cry, it's only a joke."],
          ["Howl", "Howl you know unless you open this door?"],
          ["Iran", "Iran all the way here. Let me in already!"]]

    joke_num = random.randint(0, 9)
    chosen_joke = [kk[joke_num][0], kk[joke_num][1]]
    await bot.say(chosen_joke[0])


    check = lambda m: "{} who".format(chosen_joke[0]) in m.content.lower()
    await bot.wait_for_message(author=ctx.message.author, channel=ctx.message.channel, check=check)
    await bot.say(chosen_joke[1])