discord bot waiting for message(不和谐机器人等待消息)
问题描述
因此,正如标题所示,我正在尝试让我的机器人响应某个消息.因此,在用户发送图像后,它会回复赞美,然后如果用户回复该消息并回复谢谢"之类的消息,机器人将继续回复不同的消息,但我正在尝试使用 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.
推荐答案
我们可以编写一个函数来检查许多不同的变化,然后将该函数传递给 wait_for_message
作为我们的 check代码>参数.
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?")
这篇关于不和谐机器人等待消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:不和谐机器人等待消息
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01