createMessageComponentCollector on a followUp is causing all sorts of inexplicable errors

So I don't really know how else to explain it. First and foremost, here is my code: https://pastebin.com/ezhdgMvT Now onto the explanation: In that command I pasted above, when I run it, if certain conditions are met (countCheck.Character2 not being null, plus the switch case being either ab or arch), it requires me to use two string menus (one when the user first runs the command, and another after the user picks an option from the 1st string menu), but upon picking the option from the 2nd string menu, the bot simply crashes, and the error is the most unhelpful of all time as it actually seems to be random, even going as far as presenting the error (sometimes) on an unrelated command that works fine on its own and causes no issues whatsoever.
Pastebin
const { SlashCommandBuilder, ActionRowBuilder, StringSelectMenuBuil...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
20 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!
The_DayStar
The_DayStar10mo ago
My discord is version 14.13.0 My node is v18.17.0
monbrey
monbrey10mo ago
It would still be helpful to us to know what the errors are
The_DayStar
The_DayStar10mo ago
So j.reply instead of interaction.followUp? As I said before, the errors seem to randomize each time, but here is an instance of me running the command, crashing the bot, restarting the bot, running the command and using the exact same choices and options on it, yet getting two different errors in two different unrelated commands despite not being interconnected to one another, and despite no changes happening in the code in between restarts:
PS D:\downloads\Bot> node .
Connected to MongoDB/Mongoose Database.
D:\downloads\Bot\commands\player\stats.js:215
const souls = await soulsSchema.findOne({ Username: data.Username });
^

TypeError: Cannot read properties of null (reading 'Username')
at InteractionCollector.<anonymous> (D:\downloads\Bot\commands\player\stats.js:215:62)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v18.17.0
PS D:\downloads\Bot> ^C
PS D:\downloads\Bot> node .
Connected to MongoDB/Mongoose Database.
D:\downloads\Bot\commands\player\progress.js:224
if (data.PP == 0) {
^

TypeError: Cannot read properties of null (reading 'PP')
at InteractionCollector.<anonymous> (D:\downloads\Bot\commands\player\progress.js:224:14)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v18.17.0
PS D:\downloads\Bot>
PS D:\downloads\Bot> node .
Connected to MongoDB/Mongoose Database.
D:\downloads\Bot\commands\player\stats.js:215
const souls = await soulsSchema.findOne({ Username: data.Username });
^

TypeError: Cannot read properties of null (reading 'Username')
at InteractionCollector.<anonymous> (D:\downloads\Bot\commands\player\stats.js:215:62)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v18.17.0
PS D:\downloads\Bot> ^C
PS D:\downloads\Bot> node .
Connected to MongoDB/Mongoose Database.
D:\downloads\Bot\commands\player\progress.js:224
if (data.PP == 0) {
^

TypeError: Cannot read properties of null (reading 'PP')
at InteractionCollector.<anonymous> (D:\downloads\Bot\commands\player\progress.js:224:14)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v18.17.0
PS D:\downloads\Bot>
They can't be database errors, because when the command is run without the double menu, it works perfectly despite using the same queries. If you check the pastebin of the command, you can see that it only uses two menus when countCheck.Character2 !== null then switch case is either ab or arch. In any other instance, it only requires sending one (or zero menus) despite using the same db collections and queries and saves... No issue on those cases. Still looking for help with this if anyone can help
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
The_DayStar
The_DayStar10mo ago
Then why does it work when there's only one menu (and therefore the createMessageComponentCollector is used on a reply rather than a followUp), despite using the same database, the same query, the same fields, the same values and the same calculation?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
The_DayStar
The_DayStar10mo ago
Okay, but how is the data not null when I'm using createMessageComponentCollector on a reply, but is somehow null when used on a followUp? Additionally, how does it inexplicably give me the error message from a completely unrelated command? The command with the problem is progress, and yet as you can see in the first error, it's outlying the stats command for some inexplicable reason.
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
The_DayStar
The_DayStar10mo ago
let choice2;
if (selection === 'first') choice2 = countCheck.Character1;
else if (selection === 'second') choice2 = countCheck.Character2;
const data = await structureSchema.findById(choice2);
let choice2;
if (selection === 'first') choice2 = countCheck.Character1;
else if (selection === 'second') choice2 = countCheck.Character2;
const data = await structureSchema.findById(choice2);
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
The_DayStar
The_DayStar10mo ago
It's getting the objectId from the database and then fetching another document using that objectId Yes. I give it the Id, it returns a document with that _id
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
The_DayStar
The_DayStar10mo ago
I use this method in other commands and it works flawlessly. I know. But my problem isn't a database one, despite what you and Qjuh keep insisting on. If it were a database problem, why would it mention an unrelated command? And why would it work when there's only a single menu but fail with two menus? Again, the database is the same in all instances, the queries are the same, the collections and fields are the same. The only differences are the amount of menus (0, 1 or 2), and whether I'm collecting a component response from a reply or a followUp
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
The_DayStar
The_DayStar10mo ago
But you both keep saying it's a database issue while continuously ignoring my valid arguments as to why it's not at all database related.
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
The_DayStar
The_DayStar10mo ago
But I already told you why it isn't database related, multiple times... - I am running the exact same query in that exact same command just an if-statement above, using one menu instead of two, the process works flawlessly without a hitch whatsoever. - The errors are random and different each time the command with the double menu is run, despite no code or option/choices being changed. - The errors even go as far as mentioning completely unrelated commands. Here, now I completely removed this portion of the code:
const chosenAbility = await Ability.findOne({ name: pick });
let cost;
if (chosenAbility.tier === 1) {cost = 2;}
else if (chosenAbility.tier === 2) {cost = 3;}
else if (chosenAbility.tier === 3) {cost = 5;}
else if (chosenAbility.tier === 4) {cost = 7;}
else if (chosenAbility.tier === 5) {cost = 10;}

if (cost > data.PP) {
l.update({ content: `${data.Username}, this ability costs ${cost} Progress Points, but you only have ${data.PP}!`, ephemeral: true });
}
else {
data.Abilities.push({ ability: chosenAbility._id });
if (chosenAbility.archetype === data.Archetype) {
data.Ab1t++;
}
else if (chosenAbility.archetype === data.SecondArchetype) {
data.Ab2t++;
}
data.PP -= cost;
if (chosenAbility.archetype === 'Brain Eater') {
data.HP += 10;
}
await data.save();
l.update({ content: `Congratulations ${data.Username} for spending ${cost} Progress Points to unlock the ${pick} Ability! ${data.PP} Progress Points left.` });
}
const chosenAbility = await Ability.findOne({ name: pick });
let cost;
if (chosenAbility.tier === 1) {cost = 2;}
else if (chosenAbility.tier === 2) {cost = 3;}
else if (chosenAbility.tier === 3) {cost = 5;}
else if (chosenAbility.tier === 4) {cost = 7;}
else if (chosenAbility.tier === 5) {cost = 10;}

if (cost > data.PP) {
l.update({ content: `${data.Username}, this ability costs ${cost} Progress Points, but you only have ${data.PP}!`, ephemeral: true });
}
else {
data.Abilities.push({ ability: chosenAbility._id });
if (chosenAbility.archetype === data.Archetype) {
data.Ab1t++;
}
else if (chosenAbility.archetype === data.SecondArchetype) {
data.Ab2t++;
}
data.PP -= cost;
if (chosenAbility.archetype === 'Brain Eater') {
data.HP += 10;
}
await data.save();
l.update({ content: `Congratulations ${data.Username} for spending ${cost} Progress Points to unlock the ${pick} Ability! ${data.PP} Progress Points left.` });
}
Which is what reads and writes to the database. Instead, I left it as this:
coll4.on('collect', async l => {
const pick = l.values[0];
interaction.followUp(`${pick} is what`);
});
break;
coll4.on('collect', async l => {
const pick = l.values[0];
interaction.followUp(`${pick} is what`);
});
break;
I'm still getting a random error.
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
The_DayStar
The_DayStar10mo ago
What attitude? I'm just explaining my issue...