Collections problem

javascript
const debounce = new Discord.Collection();
if (debounce.findKey(id => id === interaction.message.id)) {
console.log(1)
if (debounce[interaction.message.id].length === interaction.message.embeds[0].data.fields[1].value) {console.log(11); return; }
debounce[interaction.message.id].push(interaction.user)
} else {
console.log(2)
debounce[interaction.message.id] = [interaction.user];
}
javascript
const debounce = new Discord.Collection();
if (debounce.findKey(id => id === interaction.message.id)) {
console.log(1)
if (debounce[interaction.message.id].length === interaction.message.embeds[0].data.fields[1].value) {console.log(11); return; }
debounce[interaction.message.id].push(interaction.user)
} else {
console.log(2)
debounce[interaction.message.id] = [interaction.user];
}
does someone know why it logs 2 and only then 1? Also, why does debounce.findKey always returns undefined?
7 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Parogo_72
Parogo_723y ago
Because a collection isnt an array
DanielBA
DanielBAOP3y ago
So what should I change?
Parogo_72
Parogo_723y ago
Your last line should be collection.set(key, value)
d.js docs
d.js docs3y ago
Suggestion for @danielba:guide Additional Information: Collections read more
DanielBA
DanielBAOP3y ago
testing it out @parogo_72 How can I append values into a collection properly?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server