最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Discord Bot send a message when the user says a word in a sentence - Stack Overflow

programmeradmin3浏览0评论
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');

I want my bot to say something when the user says something that contains 'server IP' I currently have this code, but it only replies when I send 'ping', how can I make it where it detects when the word 'ping' is in the sentence?

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');

I want my bot to say something when the user says something that contains 'server IP' I currently have this code, but it only replies when I send 'ping', how can I make it where it detects when the word 'ping' is in the sentence?

Share Improve this question edited Feb 21, 2018 at 22:16 newbie 1,5711 gold badge13 silver badges21 bronze badges asked Feb 17, 2018 at 19:41 RessiiRessii 12 gold badges2 silver badges4 bronze badges 1
  • 1 stackoverflow./questions/1789945/… – Martin Smith Commented Feb 17, 2018 at 23:46
Add a ment  | 

1 Answer 1

Reset to default 1

You can use .includes(...) to check if the content (returns a string) of a message contains 'ping'.

Like so:

if(message.content.includes('ping')) {
    message.reply('Pong');
}
发布评论

评论列表(0)

  1. 暂无评论