What is the max time for a Collect Interaction?

I have a Discord bot that automatically sends the status of the translations we have for a specific app, with an Update button attached to it. what is the max time that I can pass for the collector component, as it seems that I'm unable to make use of 24 hours <_< See the following line in the following code snipper: const collector = message.createMessageComponentCollector({ filter, time: 86390999 }); (Also other tips are welcome)
try {
const response = await axios.request(options2);
const token = response.data;
const options = {
method: 'GET',
url: 'https://locize.app/api/project/<ProjectID>',
headers: {
authorization: token
}
};
const response2 = await axios.request(options);
const data = response2.data.stats.latest;

// Create embed
let embed = new EmbedBuilder()
.setTitle("Translation Completion")
.setColor("#0099ff");

for (const [language, categories] of Object.entries(data)) {
let totalSegments = 0;
let translatedSegments = 0;
for (const category of Object.values(categories)) {
totalSegments += category.segmentsTotal;
translatedSegments += category.segmentsTranslated;
}
const percentageTranslated = (translatedSegments / totalSegments) * 100;

// Add angry or happy smiley depending on the percentage
const smiley = percentageTranslated >= 95 ? "😊" : "😡";
embed.addFields({ name: `${language} ${smiley}`, value: `${percentageTranslated.toFixed(2)}%`, inline: true });

}

// Create button
const updateButton = new ButtonBuilder()
.setCustomId("update")
.setLabel("Update")
.setStyle(ButtonStyle.Primary);

const row = new ActionRowBuilder().addComponents(updateButton);

const message = await client.channels.cache.get(channelId).send({ embeds: [embed], components: [row] });

// Listen for users clicking on the button
const filter = (interaction) => interaction.isButton() && interaction.customId === "update";
const collector = message.createMessageComponentCollector({ filter, time: 86390999 });

collector.on("collect", async (interaction) => {
// Update the embed values
const options = {
method: 'GET',
url: 'https://locize.app/api/project/<ProjectID>',
headers: {
authorization: token
}
};
const response2 = await axios.request(options);
const data = response2.data.stats.latest;


embed = new EmbedBuilder()
.setTitle("Translation Completion")
.setColor("#0099ff");
for (const [language, categories] of Object.entries(data)) {
let totalSegments = 0;
let translatedSegments = 0;
for (const category of Object.values(categories)) {
totalSegments += category.segmentsTotal;
translatedSegments += category.segmentsTranslated;
}
const percentageTranslated = (translatedSegments / totalSegments) * 100;

// Add angry or happy smiley depending on the percentage
const smiley = percentageTranslated >= 95 ? "😊" : "😡";
embed.addFields({ name: `${language} ${smiley}`, value: `${percentageTranslated.toFixed(2)}%`, inline: true });
}

// Update the message with the new embed
await interaction.update({ embeds: [embed] });
});

collector.on("end", async () => {
// Remove the message once the collector time has ended
await message.delete();
});


} catch (error) {
console.error(error);
}
try {
const response = await axios.request(options2);
const token = response.data;
const options = {
method: 'GET',
url: 'https://locize.app/api/project/<ProjectID>',
headers: {
authorization: token
}
};
const response2 = await axios.request(options);
const data = response2.data.stats.latest;

// Create embed
let embed = new EmbedBuilder()
.setTitle("Translation Completion")
.setColor("#0099ff");

for (const [language, categories] of Object.entries(data)) {
let totalSegments = 0;
let translatedSegments = 0;
for (const category of Object.values(categories)) {
totalSegments += category.segmentsTotal;
translatedSegments += category.segmentsTranslated;
}
const percentageTranslated = (translatedSegments / totalSegments) * 100;

// Add angry or happy smiley depending on the percentage
const smiley = percentageTranslated >= 95 ? "😊" : "😡";
embed.addFields({ name: `${language} ${smiley}`, value: `${percentageTranslated.toFixed(2)}%`, inline: true });

}

// Create button
const updateButton = new ButtonBuilder()
.setCustomId("update")
.setLabel("Update")
.setStyle(ButtonStyle.Primary);

const row = new ActionRowBuilder().addComponents(updateButton);

const message = await client.channels.cache.get(channelId).send({ embeds: [embed], components: [row] });

// Listen for users clicking on the button
const filter = (interaction) => interaction.isButton() && interaction.customId === "update";
const collector = message.createMessageComponentCollector({ filter, time: 86390999 });

collector.on("collect", async (interaction) => {
// Update the embed values
const options = {
method: 'GET',
url: 'https://locize.app/api/project/<ProjectID>',
headers: {
authorization: token
}
};
const response2 = await axios.request(options);
const data = response2.data.stats.latest;


embed = new EmbedBuilder()
.setTitle("Translation Completion")
.setColor("#0099ff");
for (const [language, categories] of Object.entries(data)) {
let totalSegments = 0;
let translatedSegments = 0;
for (const category of Object.values(categories)) {
totalSegments += category.segmentsTotal;
translatedSegments += category.segmentsTranslated;
}
const percentageTranslated = (translatedSegments / totalSegments) * 100;

// Add angry or happy smiley depending on the percentage
const smiley = percentageTranslated >= 95 ? "😊" : "😡";
embed.addFields({ name: `${language} ${smiley}`, value: `${percentageTranslated.toFixed(2)}%`, inline: true });
}

// Update the message with the new embed
await interaction.update({ embeds: [embed] });
});

collector.on("end", async () => {
// Remove the message once the collector time has ended
await message.delete();
});


} catch (error) {
console.error(error);
}
No description
3 Replies
d.js toolkit
d.js toolkit•7mo 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!
treble/luna
treble/luna•7mo ago
Just omit the time Then it'll run untill your bot restarts Or just use the interactionCreate event
can
can•7mo ago
store data with id (generate a random id) then attach the generated id to button custom_id and handle the data with interactionCreate event