Discord Bot在用户说出句子中的单词时发送消息

时间:2018-02-17 19:41:22

标签: javascript bots discord

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'一词时检测到它?

1 个答案:

答案 0 :(得分:1)

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

像这样:

if(message.content.includes('ping')) {
    message.reply('Pong');
}
相关问题