問題描述
因此,正如標題所示,我正在嘗試讓我的機器人響應(yīng)某個消息.因此,在用戶發(fā)送圖像后,它會回復(fù)贊美,然后如果用戶回復(fù)該消息并回復(fù)謝謝"之類的消息,機器人將繼續(xù)回復(fù)不同的消息,但我正在嘗試使用 if 語句使其響應(yīng)多個版本的謝謝".這是到目前為止的代碼:
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 不打印測試并且機器人在服務(wù)器中沒有響應(yīng).
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.
推薦答案
我們可以編寫一個函數(shù)來檢查許多不同的變化,然后將該函數(shù)傳遞給 wait_for_message
作為我們的 check代碼>參數(shù).
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?")
這篇關(guān)于不和諧機器人等待消息的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!