if an insert has one of ListClaims names in .setAuthor it reacts with an emoji, that's what I want it to do, but it stops working if I put more than 1 name in ListClaims, try to use a txt but it doesn't work.
var ListClaims = ["rick sanchez","alex","juan"];
if(message.embeds.length >= 0)
// Check if the Message has embed or not
{
let embed = message.embeds
// console.log(embed) just a console.log
for(let i = 0; i < embed.length; i++)
{
if(embed[i].author.name === null) return;
// check each embed if it has setAuthor or not, if it doesnt then do nothing
{
if(embed[i].author.name.toLowerCase().includes(ListClaims))
// check each embed if it includes word
{
message.react('🎉')
}
}
}
}
You are calling includes() in a string (author.name) with an array argument. You want to run it the other way around. So instead of:
if (embed[i].author.name.toLowerCase().includes(ListClaims))
Try using:
if (ListClaims.includes(embed[i].author.name.toLowerCase()))
the js includes function can reference here
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes
the following is the sample
const array1 = [1, 2, 3];
document.write("Is array1 contain 2 : ");
document.write(array1.includes(2));
document.write("<br>");
document.write("Is array1 contain 4 : ");
document.write(array1.includes(4));
.includes is an array method, but youve used it as a string method.
Below I've fixed it while also cleaning up your code. The new code is in the messageHandler function.
const listClaims = ["rick sanchez", "alex", "juan"];
// dummy message object
const msg = {
embeds: [
{name: "alex"},
{name: null},
{name: "juan"},
],
react: (str) => console.log(str),
}
function handleMessage(msg){
if (!msg.embeds.length) return;
msg.embeds.forEach(embed => {
if (listClaims.includes(embed.name)) msg.react('🎉');
})
}
handleMessage(msg)