Problem with buttons

when i first click prefix button it works, but when i click slash button it says failed interaction on discord and no error on console.
4 Replies
d.js toolkit
d.js toolkit16mo 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!
Massicraft
MassicraftOP16mo ago
const { SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('help')
.setDescription('mostra i comandi del bot'),

async execute(interaction) {

const prefix_button = new ButtonBuilder()
.setCustomId('prefix-commands')
.setLabel('Prefix Commands')
.setStyle(ButtonStyle.Primary);

const slash_button = new ButtonBuilder()
.setCustomId('slash-commands')
.setLabel('Slash Commands')
.setStyle(ButtonStyle.Secondary)
.setDisabled(true);

const home_prefix_embed = new EmbedBuilder()
.setTitle('prefix commands')
.setDescription('questa è la home dei prefix commands')

const home_slash_embed = new EmbedBuilder()
.setTitle('slash commands')
.setDescription('questa è la home dei comandi slash')
const { SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('help')
.setDescription('mostra i comandi del bot'),

async execute(interaction) {

const prefix_button = new ButtonBuilder()
.setCustomId('prefix-commands')
.setLabel('Prefix Commands')
.setStyle(ButtonStyle.Primary);

const slash_button = new ButtonBuilder()
.setCustomId('slash-commands')
.setLabel('Slash Commands')
.setStyle(ButtonStyle.Secondary)
.setDisabled(true);

const home_prefix_embed = new EmbedBuilder()
.setTitle('prefix commands')
.setDescription('questa è la home dei prefix commands')

const home_slash_embed = new EmbedBuilder()
.setTitle('slash commands')
.setDescription('questa è la home dei comandi slash')
const row = new ActionRowBuilder()
.addComponents(prefix_button, slash_button);

const response = await interaction.reply({
content: `${interaction.member}`,
components: [row],
embeds: [home_slash_embed]
});

const collectorFilter = i => i.user.id === interaction.user.id;

const confirmation = await response.awaitMessageComponent({ filter: collectorFilter });

if (confirmation.customId === 'prefix-commands') {
slash_button.setDisabled(false);
prefix_button.setDisabled(true);
await confirmation.update({ content: `${interaction.member}`, components: [row], embeds: [home_prefix_embed] });
} else if (confirmation.customId === 'slash-commands') {
slash_button.setDisabled(true);
prefix_button.setDisabled(false);
await confirmation.update({ content: `${interaction.member}`, components: [row], embeds: [home_slash_embed] });
}

},
};
const row = new ActionRowBuilder()
.addComponents(prefix_button, slash_button);

const response = await interaction.reply({
content: `${interaction.member}`,
components: [row],
embeds: [home_slash_embed]
});

const collectorFilter = i => i.user.id === interaction.user.id;

const confirmation = await response.awaitMessageComponent({ filter: collectorFilter });

if (confirmation.customId === 'prefix-commands') {
slash_button.setDisabled(false);
prefix_button.setDisabled(true);
await confirmation.update({ content: `${interaction.member}`, components: [row], embeds: [home_prefix_embed] });
} else if (confirmation.customId === 'slash-commands') {
slash_button.setDisabled(true);
prefix_button.setDisabled(false);
await confirmation.update({ content: `${interaction.member}`, components: [row], embeds: [home_slash_embed] });
}

},
};
node -v 18.16.0 discord.js v14.11.0
!"Unkown
!"Unkown16mo ago
use createMessageComponentCollector
Massicraft
MassicraftOP16mo ago
so i just have to put const confirmation = await response.createMessageComponentCollector instead of const confirmation = await response.awaitMessageComponent ?
Want results from more Discord servers?
Add your server