不和谐的机器人等待消息 [英] discord bot waiting for message

查看:96
本文介绍了不和谐的机器人等待消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,正如标题所示,我正在尝试使我的漫游器响应特定消息。因此,在用户发送图像后,它会称赞一下,然后,如果用户使用诸​​如感谢之类的消息响应该消息,则机器人将继续以另一条消息进行响应,但我正在尝试使它使用if语句响应感谢的多​​个版本。到目前为止,这是代码:

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?")

我不确定我是否做对了,python shell没有

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.

推荐答案

我们可以编写一个函数来检查许多不同的变化,然后将该函数作为 check 参数传递给 wait_for_message

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?")

这篇关于不和谐的机器人等待消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆