Button for giveaway

const { checkJoin } = require("src/utils/functions");

module.exports = {
customId: 'gajoin_button',
async execute(interaction, client) {
const userId = interaction.user.id;
const messageId = interaction.message.id;

const gaDoc = await gaCollection.findOne({ messageId });
if (!gaDoc) {
return await interaction.reply({ content: `cant find giveaway.`, flags: 64 });
}

const alreadyJoined = Boolean(gaDoc.joined?.[userId]);

if (alreadyJoined) {
await gaCollection.updateOne(
{ messageId },
{ $unset: { [`joined.${userId}`]: "" } }
);
} else {
await gaCollection.updateOne(
{ messageId },
{ $set: { [`joined.${userId}`]: true } }
);
}

const gaDocUpdated = await gaCollection.findOne({ messageId });
const updatedRow = checkJoin(interaction, gaDocUpdated.joined);

if (interaction.message) {
await interaction.message.edit({ components: [updatedRow] }).catch(() => {});
}

if (!alreadyJoined) await interaction.deferUpdate();
else await interaction.reply({ content: `leave giveaway.`, flags: 64 });
}
};
const { checkJoin } = require("src/utils/functions");

module.exports = {
customId: 'gajoin_button',
async execute(interaction, client) {
const userId = interaction.user.id;
const messageId = interaction.message.id;

const gaDoc = await gaCollection.findOne({ messageId });
if (!gaDoc) {
return await interaction.reply({ content: `cant find giveaway.`, flags: 64 });
}

const alreadyJoined = Boolean(gaDoc.joined?.[userId]);

if (alreadyJoined) {
await gaCollection.updateOne(
{ messageId },
{ $unset: { [`joined.${userId}`]: "" } }
);
} else {
await gaCollection.updateOne(
{ messageId },
{ $set: { [`joined.${userId}`]: true } }
);
}

const gaDocUpdated = await gaCollection.findOne({ messageId });
const updatedRow = checkJoin(interaction, gaDocUpdated.joined);

if (interaction.message) {
await interaction.message.edit({ components: [updatedRow] }).catch(() => {});
}

if (!alreadyJoined) await interaction.deferUpdate();
else await interaction.reply({ content: `leave giveaway.`, flags: 64 });
}
};
15 Replies
d.js toolkit
d.js toolkit4w ago
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Chunn
ChunnOP4w ago
I don't know what the problem is but the process I did with the giveaway gave me error 10062
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Chunn
ChunnOP4w ago
Lỗi khi xử lý GA button: DiscordAPIError[10062]: Unknown interaction at handleErrors (/root/LunariBOT/node_modules/@discordjs/rest/dist/index.js:762:13) at process.processTicksAndRejections (node:internal/process/task_queues:105:5) at async BurstHandler.runRequest (/root/LunariBOT/node_modules/@discordjs/rest/dist/index.js:866:23) at async _REST.request (/root/LunariBOT/node_modules/@discordjs/rest/dist/index.js:1307:22) at async ButtonInteraction.reply (/root/LunariBOT/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:193:22) at async /root/LunariBOT/src/events/buttons/gaButton.js:50:25 at async runQueue (/root/LunariBOT/src/events/buttons/gaButton.js:66:17) { requestBody: { files: [], json: { type: 4, data: [Object] } }, rawError: { message: 'Unknown interaction', code: 10062 }, code: 10062, status: 404, method: 'POST', url: 'https://discord.com/api/v10/interactions/1433064355963863212/aW50ZXJhY3Rpb246MTQzMzA2NDM1NTk2Mzg2MzIxMjpUY0hNMlphYVRxQVp6b0VYMzUzbmxuYzFYMGIyTFc5UnpybHlpcnhEd1ZwVGtGYThtWmhpUlpmbEhtMjJ1VTZxWjFOZXRyRzdXOURBY0RFZk4yNU13Z0tzUjB0QjRuZXhaYktaY3J3TDJwUHc4R0s1cTRWRVVXSVBxNzFhMkVuSg/callback?with_response=false' }
d.js docs
d.js docs4w ago
tag suggestion for @Chunn: Common causes of DiscordAPIError[10062]: Unknown interaction: - Initial response took more than 3 seconds ➞ defer the response *. - Wrong interaction object inside a collector. - Two processes handling the same command (the first consumes the interaction, so it won't be valid for the other instance) * Note: you cannot defer modal or autocomplete value responses
Chunn
ChunnOP4w ago
@BakeWithMe sorry but i still don't know what's wrong as that button works fine with a giveaway
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Chunn
ChunnOP4w ago
it works fine when it's a normal giveaway and not a flash giveaway
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Chunn
ChunnOP4w ago
the code is the same but the difference is whether it makes 5 or 1
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Chunn
ChunnOP4w ago
5 means using the command to create 5 times in a row 1 is to use the command to create once
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
...
...4w ago
Mean you clicked the button and the command will form 5 GA. Is that right?

Did you find this page helpful?