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

前端 未结 1 944
有刺的猬
有刺的猬 2021-01-27 15:31

I am trying to make a discord bot tell jokes in Python. However, specifically with the Knock Knock jokes, I can\'t get the bot to respond after the user\'s responds with \"who\'

相关标签:
1条回答
  • 2021-01-27 16:15

    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])
    
    0 讨论(0)
提交回复
热议问题