簡體   English   中英

discord.py-機器人不響應多個連接的消息

[英]discord.py - bot doesn't respond to multiple connected messages

我試圖使一個不和諧的機器人用Python講笑話。 但是,特別是對於Knock Knock笑話,我無法讓機器人在用戶回復“誰在那兒”后做出響應。 你能幫我嗎?

@bot.command(pass_context=True)
async def joke(ctx, type):

    if type.lower() == "ym":
        yo_momma = ("fat, I took a picture of her last Christmas and it's still printing.",
               "fat when she got on the scale it said, 'I need your weight not your phone number.'",
               "fat and old when God said, 'Let there be light', he asked your mother to move out of the way.",
               "fat she doesn't need the internet, because she's already world wide.",
               "fat, when she sat on an iPod, she made the iPad!",
               "fat she walked past the TV and I missed 3 episodes.",
               "ugly when she tried to join an ugly contest they said, 'Sorry, no professionals.'",
               "ugly she made One Direction go another direction.",
               "ugly Fix-It Felix said, 'I can\'t fix it.'"
               "stupid when an intruder broke into her house, she ran downstairs, dialed 9-1-1 on the microwave, and couldn't find the 'CALL' button.",
               "stupid she stuck a battery up her ass and said, 'I GOT THE POWER!'",
               "stupid that she sat on the TV to watch the couch.")
        await bot.say("Yo momma so {}".format(random.choice(yo_momma)))

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

        if "who's there" in ctx.message.content.lower():
            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])

        if "{} who".format(chosen_joke[0]) in ctx.message.content.lower():
            await bot.say(chosen_joke[1])

您可以將wait_for_messagecheck功能一起使用,以等待來自某些具有特定內容的用戶的消息:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM