BakeWithMe
BakeWithMe
DIAdiscord.js - Imagine an app
Created by BakeWithMe on 4/20/2024 in #djs-questions
Button message not working
I want when other users who arent the interaction user get met with this message 'only user can use these buttons', but this doesnt work.
const filter = (i) => i.user.id === interaction.user.id;
const collector = interaction.channel.createMessageComponentCollector({ filter, time: 60000 });

collector.on('collect', async (i) => {
try {
if (i.user.id !== interaction.user.id) {
// User is not the original user who triggered the command
await i.reply({ content: 'Only the user who triggered the command can use these buttons', ephemeral: true });
return;
}

if (i.customId === 'prev_page') {
if (currentPage > 0) {
currentPage--;
await updateEmbed();
}
} else if (i.customId === 'next_page') {
if (currentPage < totalPages - 1) {
currentPage++;
await updateEmbed();
}
}

// Acknowledge the interaction
await i.deferUpdate();
} catch (error) {
console.error(error);
}
});

collector.on('end', () => {
const disabledButtonRow = createButtonRow(currentPage, totalPages);
disabledButtonRow.components.forEach(button => button.setDisabled(true));
interaction.editReply({ components: [disabledButtonRow] });
});
}
} catch (e) {

const filter = (i) => i.user.id === interaction.user.id;
const collector = interaction.channel.createMessageComponentCollector({ filter, time: 60000 });

collector.on('collect', async (i) => {
try {
if (i.user.id !== interaction.user.id) {
// User is not the original user who triggered the command
await i.reply({ content: 'Only the user who triggered the command can use these buttons', ephemeral: true });
return;
}

if (i.customId === 'prev_page') {
if (currentPage > 0) {
currentPage--;
await updateEmbed();
}
} else if (i.customId === 'next_page') {
if (currentPage < totalPages - 1) {
currentPage++;
await updateEmbed();
}
}

// Acknowledge the interaction
await i.deferUpdate();
} catch (error) {
console.error(error);
}
});

collector.on('end', () => {
const disabledButtonRow = createButtonRow(currentPage, totalPages);
disabledButtonRow.components.forEach(button => button.setDisabled(true));
interaction.editReply({ components: [disabledButtonRow] });
});
}
} catch (e) {

6 replies
DIAdiscord.js - Imagine an app
Created by BakeWithMe on 3/23/2024 in #djs-questions
embed not working sometimes on random cat image command
I have this command that sends a random cat image from an image link. Sometimes they arent embedding and sometimes they are, is this a discord issue or do i have to change something in my code?
6 replies
DIAdiscord.js - Imagine an app
Created by BakeWithMe on 3/22/2024 in #djs-questions
Error in translate command "Unknown interaction"
Hello, this is a code for a translate command via contextmenu command, i cant figure out what in the code is causing this error. This error occurs sometimes. Can anyone with more coding experience than me see what could be the issue.
Error while replying to interaction: DiscordAPIError[10062]: Unknown interaction
at handleErrors (/home/container/node_modules/discord.js/node_modules/@discordjs/rest/dist/index.js:722:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (/home/container/node_modules/discord.js/node_modules/@discordjs/rest/dist/index.js:826:23)
at async _REST.request (/home/container/node_modules/discord.js/node_modules/@discordjs/rest/dist/index.js:1266:22)
at async MessageContextMenuCommandInteraction.reply (/home/container/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:111:5)
at async Object.run (/home/container/slashCommands/context/translate.js:156:7)
at async Client.<anonymous> (/home/container/events/interactionCreate.js:77:13) {
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/1220771689877733456/aW50ZXJhY3Rpb246MTIyMDc3MTY4OTg3NzczMzQ1NjpuSXdBaHNURHBIMUxlNVJja3RaVzVCaXJzeTU3bWNhMTBmR2lVeUo2eG5RMm1jT1pZaGcxVENjSDl6ZnU5bTFtV1VzWmZ6bGNpRkd1SkdPTUJoRnFjZFN0UWRycUUzTkJTUWFQNzg0amQ1TURRS0pvS0FzQnFJcmJ0RFB0MmhMQg/callback'
}
Error while replying to interaction: DiscordAPIError[10062]: Unknown interaction
at handleErrors (/home/container/node_modules/discord.js/node_modules/@discordjs/rest/dist/index.js:722:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (/home/container/node_modules/discord.js/node_modules/@discordjs/rest/dist/index.js:826:23)
at async _REST.request (/home/container/node_modules/discord.js/node_modules/@discordjs/rest/dist/index.js:1266:22)
at async MessageContextMenuCommandInteraction.reply (/home/container/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:111:5)
at async Object.run (/home/container/slashCommands/context/translate.js:156:7)
at async Client.<anonymous> (/home/container/events/interactionCreate.js:77:13) {
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/1220771689877733456/aW50ZXJhY3Rpb246MTIyMDc3MTY4OTg3NzczMzQ1NjpuSXdBaHNURHBIMUxlNVJja3RaVzVCaXJzeTU3bWNhMTBmR2lVeUo2eG5RMm1jT1pZaGcxVENjSDl6ZnU5bTFtV1VzWmZ6bGNpRkd1SkdPTUJoRnFjZFN0UWRycUUzTkJTUWFQNzg0amQ1TURRS0pvS0FzQnFJcmJ0RFB0MmhMQg/callback'
}
14 replies
DIAdiscord.js - Imagine an app
Created by BakeWithMe on 3/18/2024 in #djs-questions
ephemeral not working
Can anyone take a look at my code to why the ephemeral responses arent appearing as ephemeral
4 replies
DIAdiscord.js - Imagine an app
Created by BakeWithMe on 11/5/2022 in #djs-questions
Set slash command only visible by user
Im new to this and idk how to set a slash command to be only visible by the one doing it
8 replies