簡體   English   中英

如何使 discord 機器人響應其他消息中的不同(多個)關鍵字?

[英]How to make the discord bot respond different (multiple) keywords in the others message?

我想知道如何使 discord 機器人在其他消息中響應不同(多個)關鍵字。 這就是我想要它做的事情:


情況1:


Discord 用戶:嗨


Bot:打擾一下,你在跟我說話嗎?



案例二:


Discord 用戶:嗨機器人


機器人:哦,嗨


這是我嘗試過的代碼:

@bot.event
async def on_message(message):
    if message.author == bot.user:
        return
    if "Hi" in message.content or "hi" in message.content or "Hello" in message.content or "hello" in message.content:
        if "Adam" not in message.content or "ADAM" not in message.content or "adam" not in message.content or "everyone" not in message.content or "Everyone" not in message.content or "EVERYONE" not in message.content or "everybody" not in message.content or "Everybody" not in message.content or "EVERYBODY" not in message.content:
            random_msg_greeting_1 = random.randint(1,3)
            if random_msg_greeting_1 == 1:
                await message.channel.send("Oh are you saying Hello to me?")
            elif random_msg_greeting_1 == 2:
                await message.channel.send("Oh are you talking to me?")
            elif random_msg_greeting_1 == 3:
                await message.channel.send("Hmmmmmm... are you talking to me? (Hello?)")

        else:
            random_msg_greeting_2 = random.randint(1,3)
            if random_msg_greeting_2 == 1:
                await message.channel.send ("Hello!")
            elif random_msg_greeting_2 == 2:
                await message.channel.send("Hi!")
            elif random_msg_greeting_2 == 3:
                await message.channel.send ("Oh hi!!!")

這是結果:


我:你好


ADAM(我的機器人):哦,你在跟我說話嗎?


我:嗨亞當!


亞當:嗯嗯……你在跟我說話嗎? (你好?)


我希望他在一條消息中識別多個關鍵字,就像這里我希望他能夠通過檢查諸如“嗨”之類的關鍵字來判斷是否有人在打招呼。 並通過檢查諸如“ADAM”之類的關鍵字來判斷是否有人在與他交談。

如果你知道我應該怎么做,請指導我。 我非常需要你的幫助。 謝謝!

修復了你亂七八糟的代碼。 但是如果你想制作一個聊天機器人,你需要使用語言處理之類的東西

@bot.event
async def on_message(message):
    if message.author.id == bot.user.id:
        return
    if "hi" in message.content.lower() or "hello" in message.content.lower():
        if "adam" in message.content.lower():
            random_msg_greeting_1 = random.randint(1,3)
            if random_msg_greeting_1 == 1:
                await message.channel.send("Hello!")
            elif random_msg_greeting_1 == 2:
                await message.channel.send("Hi!")
            elif random_msg_greeting_1 == 3:
                await message.channel.send ("Oh hi!!!")

        else:
            random_msg_greeting_2 = random.randint(1,3)
            if random_msg_greeting_2 == 1:
                await message.channel.send("Oh are you saying Hello to me?")
            elif random_msg_greeting_2 == 2:
                await message.channel.send("Oh are you talking to me?")
            elif random_msg_greeting_2 == 3:
                await message.channel.send("Hmmmmmm... are you talking to me? (Hello?)")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM