[英]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(...)
来检查message
的content
(返回字符串)是否包含“ping”。
像这样:
if(message.content.includes('ping')) {
message.reply('Pong');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.