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

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

您可以使用.includes(...)来检查messagecontent (返回字符串)是否包含“ping”。

像这样:

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

暂无
暂无

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

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