简体   繁体   English

如何使 discord 机器人响应其他消息中的不同(多个)关键字?

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

I'd like to know how to make the discord bot respond differently (multiple) keywords in the others message.我想知道如何使 discord 机器人在其他消息中响应不同(多个)关键字。 Here's what I want it to do:这就是我想要它做的事情:


Case 1:情况1:


Discord User: Hi Discord 用户:嗨


Bot: Excesue me, are you talking to me? Bot:打扰一下,你在跟我说话吗?



Case 2:案例二:


Discord User: Hi bot Discord 用户:嗨机器人


Bot: Oh hi机器人:哦,嗨


Here is the code that I have tried:这是我尝试过的代码:

@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!!!")

And this is the result:这是结果:


Me: Hi我:你好


ADAM (my bot): Oh are you talking to me? ADAM(我的机器人):哦,你在跟我说话吗?


Me: Hi ADAM!我:嗨亚当!


ADAM: Hmmmmmm... are you talking to me?亚当:嗯嗯……你在跟我说话吗? (Hello?) (你好?)


I want him to recognize multiple keywords in one message, like here I want him to be able to tell if someone is saying hello by checking for keywords like "Hi".我希望他在一条消息中识别多个关键字,就像这里我希望他能够通过检查诸如“嗨”之类的关键字来判断是否有人在打招呼。 And by checking for keywords like "ADAM" to tell if someone is talking to him.并通过检查诸如“ADAM”之类的关键字来判断是否有人在与他交谈。

If you know what I should do, please guide me.如果你知道我应该怎么做,请指导我。 I desperately need your help.我非常需要你的帮助。 Thank you!谢谢!

Fixed your messy code.修复了你乱七八糟的代码。 But you need to use something like language processing for it if you want to make a chatbot但是如果你想制作一个聊天机器人,你需要使用语言处理之类的东西

@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