Bot来回复消息的一部分


client.on('message', msg => {
if (msg.content === 'good morning!')
msg.reply('morning!');
}
);

当我说";早上好&";,但是如果我想让它回复类似";我刚醒来,早上好"我并不是这个意思,我只是说如果触发消息在另一个消息的中间

您可以使用String.prototype.includes()函数,无论字符串是否包含给定的参数,该函数都将返回boolean

const message = 'Happy Birthday Random Person!';
const otherMessage = 'Happy Birthday Person I Know!';
if (message.toLowerCase().includes('random person'))
console.log("You shouldn't be talking to random people on the internet >:(");

if (otherMessage.toLowerCase().includes('random person'))
console.log("You shouldn't be talking to random people on the internet >:(");
else console.log('Good, you were being safe ༼ つ ◕_◕ ༽つ')

if (message.content.toLowerCase().includes('good morning')) {
// do stuff
};

最新更新