【问题标题】:Discord Bot send a message when the user says a word in a sentence当用户说出句子中的一个词时,Discord Bot 会发送消息
【发布时间】:2018-07-28 10:48:22
【问题描述】:
const Discord = require('discord.js');
const bot = new Discord.Client();

bot.on('message', (message) => {
    if(message.content == 'ping') {
        message.reply('Pong');
    }
});

bot.login('my token is here');

当用户说出包含“服务器 IP”的内容时,我希望我的机器人说些什么 我目前有这个代码,但它只在我发送“ping”时回复,我怎样才能让它检测到句子中是否有“ping”这个词?

【问题讨论】:

标签: javascript bots discord


【解决方案1】:

您可以使用.includes(...) 检查messagecontent(返回字符串)是否包含“ping”。

像这样:

if(message.content.includes('ping')) {
    message.reply('Pong');
}

【讨论】:

    猜你喜欢
    • 2020-12-24
    • 2020-07-31
    • 2021-05-15
    • 2021-09-30
    • 1970-01-01
    • 2019-01-16
    • 2021-07-26
    • 1970-01-01
    • 2020-12-01
    相关资源
    最近更新 更多