gpt4 book ai didi

javascript - 如何让很多词都触发同样的事情

转载 作者:行者123 更新时间:2023-11-30 11:11:05 24 4
gpt4 key购买 nike

我想要的是 can、is 和 was 这三个词来触发相同的代码。如果文本中可以、是或曾经是,我不希望运行第一位,而是运行第二位。

bot.on ('message', function (message){
const words = message.content.split(' ');

if(words.includes('sans'))
{
const words = message.content.split(' ');
if(!message.content.includes ('can', 'is', 'was'))
{
if(message.author.bot) return;
var chance = Math.floor(Math.random() * 2);
if(chance == 0)
{
message.channel.send('<:annoying_sans:520355361425981440>');
}
if(chance == 1)
{
message.channel.send('<:sans:519723756403425294>');
}
}
else
{
var chance = Math.floor(Math.random() * 3);
if(chance == 0)
{
message.channel.send('Maybe.');
}
if(chance == 1)
{
message.channel.send('Yes.');
}
if(chance == 2)
{
message.channel.send('No.');
}

}

}
});

最佳答案

首先,您要创建一个您从未使用过的名为“words”的数组。

此外,您必须遍历数组中的每个项目以检查其中的每个字符串。

此外,如果消息包含这三个词中的任何一个,您没有向我们提供应该触发的代码,但是如果不包含它们会触发什么。

此外,您正在创建一个同名的常量变量两次。

bot.on ('message', function (message){
const words = message.content.split(' ');
if(words.includes('sans')){
var questionwords = ['can', 'is', 'was',];
for (i in questionwords) {
if(words.includes(questionwords[i])) {
if(message.author.bot) return;
message.channel.send('<:download:519723756403425294>');
return;
}
}
}

以此为指导,不要只是复制粘贴

关于javascript - 如何让很多词都触发同样的事情,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53642032/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com