简体   繁体   中英

Discord Bot send a message when the user says a word in a 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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM