简体   繁体   English

当用户在句子中说出一个词时,Discord Bot 发送消息

[英]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?我希望我的机器人在用户说包含“服务器 IP”的内容时说些什么我目前有这个代码,但它只在我发送“ping”时才回复,我怎样才能让它检测到“ping”这个词在句子中?

You can use .includes(...) to check if the content (returns a string) of a message contains 'ping'.您可以使用.includes(...)来检查messagecontent (返回字符串)是否包含“ping”。

Like so:像这样:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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