This interaction failed, button not working, djs v14

8 Replies
d.js toolkit
d.js toolkit3d 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! - Marked as resolved by OP
ScremerMemer
ScremerMemerOP3d ago
Not able to figure out why this button isn't working, please help
No description
d.js docs
d.js docs3d ago
To share long code snippets, use a service like gist, sourcebin, pastebin, or similar instead of posting them as large code blocks or files.
ScremerMemer
ScremerMemerOP3d ago
Button handler:
const fs = require('fs');
const path = require('path');

module.exports = (client) => {
const buttonsPath = path.join(__dirname, '../../buttons');
const buttonFolders = fs.readdirSync(buttonsPath)
.filter(folder => !folder.startsWith('.'));

for (const folder of buttonFolders) {
const buttonFiles = fs.readdirSync(path.join(buttonsPath, folder)).filter(file => file.endsWith('.js') && !file.startsWith('.'));

for (const file of buttonFiles) {
const filePath = path.join(buttonsPath, folder, file);
const button = require(filePath);

if ('customId' in button && 'execute' in button) {
client.buttons.set(button.customId, button);
} else {
console.log(`[WARNING] The button at ${filePath} is missing required "customId" or "execute" property.`);
}
}
}
};
const fs = require('fs');
const path = require('path');

module.exports = (client) => {
const buttonsPath = path.join(__dirname, '../../buttons');
const buttonFolders = fs.readdirSync(buttonsPath)
.filter(folder => !folder.startsWith('.'));

for (const folder of buttonFolders) {
const buttonFiles = fs.readdirSync(path.join(buttonsPath, folder)).filter(file => file.endsWith('.js') && !file.startsWith('.'));

for (const file of buttonFiles) {
const filePath = path.join(buttonsPath, folder, file);
const button = require(filePath);

if ('customId' in button && 'execute' in button) {
client.buttons.set(button.customId, button);
} else {
console.log(`[WARNING] The button at ${filePath} is missing required "customId" or "execute" property.`);
}
}
}
};
Code that sends this message: https://srcb.in/rO19rzGTnq When the user clicks this button the message is shown:
const { ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
const GuildSettings = require('../../models/GuildSettings');
const { generatePreviewEmbed } = require('../../commands/setup');

module.exports = {
customId: 'setup_preview',
async execute(interaction) {
try {
const settings = await GuildSettings.findOne({ guildId: interaction.guildId });
const embed = generatePreviewEmbed(settings);

const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('setup_preview_back')
.setLabel('Back to Setup')
.setStyle(ButtonStyle.Secondary)
.setEmoji('⬅️')
);

await interaction.update({
embeds: [embed],
components: [row],
ephemeral: true
});
} catch (error) {
console.error('Error in preview:', error);
await interaction.reply({
content: 'An error occurred while showing preview.',
ephemeral: true
});
}
}
};
const { ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
const GuildSettings = require('../../models/GuildSettings');
const { generatePreviewEmbed } = require('../../commands/setup');

module.exports = {
customId: 'setup_preview',
async execute(interaction) {
try {
const settings = await GuildSettings.findOne({ guildId: interaction.guildId });
const embed = generatePreviewEmbed(settings);

const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('setup_preview_back')
.setLabel('Back to Setup')
.setStyle(ButtonStyle.Secondary)
.setEmoji('⬅️')
);

await interaction.update({
embeds: [embed],
components: [row],
ephemeral: true
});
} catch (error) {
console.error('Error in preview:', error);
await interaction.reply({
content: 'An error occurred while showing preview.',
ephemeral: true
});
}
}
};
https://srcb.in/9DNRM8MmQL ok thanks ill try Yes that works thanks, but I'm trying to make sure that the Back button takes me back to the panel i previously was in and not just the first panel, how do u think i can go about this ok let me try it out
ScremerMemer
ScremerMemerOP3d ago
Not able to implement it again: Button that sends embed: https://sourceb.in/QAR25tN2Dd Button you see in the screenshot: https://sourceb.in/RwPCnkfGXH
No description
d.js docs
d.js docs3d ago
If you aren't getting any errors, try to place console.log checkpoints throughout your code to find out where execution stops. - Once you do, log relevant values and if-conditions - More sophisticated debugging methods are breakpoints and runtime inspections: learn more
ScremerMemer
ScremerMemerOP3d ago
I tried logging things in the console and it says it cant find the lastSetupPanel, I tried fixing it but I couldn't please help. Button that sends embed: https://sourceb.in/EUrMPLmQwp Button you see in the screenshot: https://sourceb.in/C4MtsZxrgi
No description
ScremerMemer
ScremerMemerOP3d ago
mb i wasnt thinking at all, thanks for ur inputs it works now
Want results from more Discord servers?
Add your server