discord bot waiting for message

不羁岁月 提交于 2020-08-10 19:08:07

问题


So as the title suggests I'm trying to make my bot respond to a certain message. So after a user sends an image, it'll respond with a compliment, then if the user RESPONDS TO THAT MESSAGE with a message such as "thanks" the bot will then go on to respond with a different message, but I'm trying to make it respond to multiple versions of "thanks" using if statements. This is the code so far:

if '.png' in message.content or '.jpg' in message.content or '.jpeg' in message.content:
            await bot.send_message(message.channel, "woah, very nice!")
            msg = await bot.wait_for_message(author=message.author)
            if msg:
                if msg.content == 'thanks':
                    print("test") 
                    await bot.send_message(message.channel, "hey, gotta compliment nice images right?")

i'm not sure if I'm doing this right, the python shell doesn't print test and the the bot doesn't respond in the server.


回答1:


We can write a function that checks for many different variations, then pass that function to wait_for_message as our check argument.

thanks = ['thanks', 'thank you', 'thx']

def thanks_check(message):
    content = message.content.lower()
    return any(t in content for t in thanks)

@bot.event
async def on_message(message):
    content = message.content.lower()
    if '.png' in content or '.jpg' in content or '.jpeg' in content:
                await bot.send_message(message.channel, "woah, very nice!")
                print("Waiting for test")
                msg = await bot.wait_for_message(author=message.author, check=thanks_check)
                if msg:
                    print("test") 
                    await bot.send_message(message.channel, "hey, gotta compliment nice images right?")


来源:https://stackoverflow.com/questions/52822769/discord-bot-waiting-for-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!