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
1 Answer
Reset to default 1You 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');
}