message collector filter not working as intended

Hello, I'm trying to build a message collector that only collects specific numbers or phrases for a bot for a game community. In doing so, I'm not sure why this logic isn't working. Is there another logic I can use or a change to the syntax I can use that will help me get the reply to be edited at the bottom of my code?
const collectorFilter = (m) => m.user.id === interaction.user.id && m.content.includes(
1 || "FC" || "fc" || "FC Items" || "Fc Items" || "fc items" ||
2 || "dow" || "DoW" || "Disciple of War" || "disciple of war" || "War" || "war" ||
3 || "dol" || "DoL" || "Disciple of Land" || "disciple of land" || "Land" || "land" ||
4 || "Glamour Items" || "glamour items" || "Glam" || "glam" || "Glamour" || "glamour" ||
5 || "Housing Items" || "housing items" || "Housing" || "housing" || "House" || "house");
const collector = interaction.channel.createMessageCollector({ filter: collectorFilter, time: 15_000, max: 1});

collector.on('collect', m => {
if (m.contains( 1 || "FC" || "fc" || "FC Items" || "Fc Items" || "fc items")){
interaction.editReply({
content: "collector is working"
});
}
});

collector.on('end', collected => {
console.log(`Collected ${collected.size} items`);
});
const collectorFilter = (m) => m.user.id === interaction.user.id && m.content.includes(
1 || "FC" || "fc" || "FC Items" || "Fc Items" || "fc items" ||
2 || "dow" || "DoW" || "Disciple of War" || "disciple of war" || "War" || "war" ||
3 || "dol" || "DoL" || "Disciple of Land" || "disciple of land" || "Land" || "land" ||
4 || "Glamour Items" || "glamour items" || "Glam" || "glam" || "Glamour" || "glamour" ||
5 || "Housing Items" || "housing items" || "Housing" || "housing" || "House" || "house");
const collector = interaction.channel.createMessageCollector({ filter: collectorFilter, time: 15_000, max: 1});

collector.on('collect', m => {
if (m.contains( 1 || "FC" || "fc" || "FC Items" || "Fc Items" || "fc items")){
interaction.editReply({
content: "collector is working"
});
}
});

collector.on('end', collected => {
console.log(`Collected ${collected.size} items`);
});
5 Replies
d.js toolkit
d.js toolkit10mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by staff
monbrey
monbrey10mo ago
That isn't even close to how includes works, you can't slap an || inside it You would need an array of words, and do words.some(word => m.content.includes(word)) This is not a discord.js issue though, just for future reference, it would belong in #other-js-ts
Snapper
SnapperOP10mo ago
Thank you!
Requiem
Requiem10mo ago
also contains returns the index value of the first occurance of specified value in array, if value is not found it will return -1. While includes return boolean value. As he said, your argument must be an array or a single string (array in your case). Define phrases in array and check if the message content includes anything from phrases array And you can use || but it would be:
if(m.includes(“FC”) || m.includes(“fc items”) || m.includes(“fc”)) etc.
if(m.includes(“FC”) || m.includes(“fc items”) || m.includes(“fc”)) etc.
1 sec Another tip, you can use m.toLowerCase().includes(phrases) and then you won’t need to add extra items to your array such as “FC”/“FC ITEMS” to handle uppercases Doesnt it technically work with arrays even though its used for nodes and token list Yeah I am refering to that Didnt use it in nodejs just in web development But I think I used a library for that, not a built-in function
Snapper
SnapperOP10mo ago
thank you!
Want results from more Discord servers?
Add your server