Interaction Create and Button Error

Terminal:
No command matching buttons was found.
Error executing buttons
TypeError: Cannot read properties of undefined (reading 'execute')
at Object.execute (C:\Users\jorre\OneDrive\Desktop\Xen\Src\Events\Creates\interactionCreate.js:16:23)
at Client.<anonymous> (C:\Users\jorre\OneDrive\Desktop\Xen\Src\Core\index.js:74:54)
at Client.emit (node:events:518:28)
at InteractionCreateAction.handle (C:\Users\jorre\OneDrive\Desktop\Xen\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\jorre\OneDrive\Desktop\Xen\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js
:4:36)
No command matching buttons was found.
Error executing buttons
TypeError: Cannot read properties of undefined (reading 'execute')
at Object.execute (C:\Users\jorre\OneDrive\Desktop\Xen\Src\Events\Creates\interactionCreate.js:16:23)
at Client.<anonymous> (C:\Users\jorre\OneDrive\Desktop\Xen\Src\Core\index.js:74:54)
at Client.emit (node:events:518:28)
at InteractionCreateAction.handle (C:\Users\jorre\OneDrive\Desktop\Xen\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\jorre\OneDrive\Desktop\Xen\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js
:4:36)
InteractionCreate.js:
const { Events } = require("discord.js");

module.exports = {
name: Events.InteractionCreate,
async execute(interaction) {
if (interaction.isChatInputCommand()) {
const command = interaction.client.commands.get(interaction.commandName);

if (!command) {
console.error(
`No command matching ${interaction.commandName} was found.`
);
}

try {
await command.execute(interaction);
} catch (error) {
console.error(`Error executing ${interaction.commandName}`);
console.error(error);
}
} else if (interaction.isButton()) {
const button = interaction.client.buttons.get(button.customId);

if (!button) {
console.error(`No button matching ${button.customId} was found.`);
}

try {
await button.execute(button);
} catch (error) {
console.error(`Error executing ${interaction.customId}`);
console.error(error);
}
} else if (interaction.isStringSelectMenu()) {
const selectMenu = interaction.client.selectMenus.get(
interaction.customId
);

if (!selectMenu) {
console.error(
`No select menu matching ${interaction.customId} was found.`
);
}

try {
await selectMenu.execute(selectMenu);
} catch (error) {
console.error(`Error executing ${interaction.customId}`);
console.error(error);
}
} else if (interaction.isModalSubmit()) {
const modal = interaction.client.modals.get(interaction.customId);

if (!modal) {
console.error(`No modal matching ${interaction.customId} was found.`);
}

try {
await modal.execute(modal, interaction);
} catch (error) {
console.error(`Error executing ${interaction.customId}`);
console.error(error);
}
}
},
};
const { Events } = require("discord.js");

module.exports = {
name: Events.InteractionCreate,
async execute(interaction) {
if (interaction.isChatInputCommand()) {
const command = interaction.client.commands.get(interaction.commandName);

if (!command) {
console.error(
`No command matching ${interaction.commandName} was found.`
);
}

try {
await command.execute(interaction);
} catch (error) {
console.error(`Error executing ${interaction.commandName}`);
console.error(error);
}
} else if (interaction.isButton()) {
const button = interaction.client.buttons.get(button.customId);

if (!button) {
console.error(`No button matching ${button.customId} was found.`);
}

try {
await button.execute(button);
} catch (error) {
console.error(`Error executing ${interaction.customId}`);
console.error(error);
}
} else if (interaction.isStringSelectMenu()) {
const selectMenu = interaction.client.selectMenus.get(
interaction.customId
);

if (!selectMenu) {
console.error(
`No select menu matching ${interaction.customId} was found.`
);
}

try {
await selectMenu.execute(selectMenu);
} catch (error) {
console.error(`Error executing ${interaction.customId}`);
console.error(error);
}
} else if (interaction.isModalSubmit()) {
const modal = interaction.client.modals.get(interaction.customId);

if (!modal) {
console.error(`No modal matching ${interaction.customId} was found.`);
}

try {
await modal.execute(modal, interaction);
} catch (error) {
console.error(`Error executing ${interaction.customId}`);
console.error(error);
}
}
},
};
buttons.js:
const { SlashCommandBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('buttons')
.setDescription('Testing buttons'),

async execute(interaction) {
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('primary')
.setLabel('Primary')
.setStyle(ButtonStyle.Primary),
new ButtonBuilder()
.setCustomId('secondary')
.setLabel('Secondary')
.setStyle(ButtonStyle.Secondary),
new ButtonBuilder()
.setCustomId('success')
.setLabel('Success')
.setStyle(ButtonStyle.Success),
new ButtonBuilder()
.setCustomId('danger')
.setLabel('Danger')
.setStyle(ButtonStyle.Danger),
new ButtonBuilder()
.setCustomId('link')
.setLabel('Link')
.setStyle(ButtonStyle.Link),
);

await interaction.reply({ content: 'Testing buttons', components: [row] });

}
}
const { SlashCommandBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('buttons')
.setDescription('Testing buttons'),

async execute(interaction) {
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('primary')
.setLabel('Primary')
.setStyle(ButtonStyle.Primary),
new ButtonBuilder()
.setCustomId('secondary')
.setLabel('Secondary')
.setStyle(ButtonStyle.Secondary),
new ButtonBuilder()
.setCustomId('success')
.setLabel('Success')
.setStyle(ButtonStyle.Success),
new ButtonBuilder()
.setCustomId('danger')
.setLabel('Danger')
.setStyle(ButtonStyle.Danger),
new ButtonBuilder()
.setCustomId('link')
.setLabel('Link')
.setStyle(ButtonStyle.Link),
);

await interaction.reply({ content: 'Testing buttons', components: [row] });

}
}
17 Replies
d.js toolkit
d.js toolkit9mo 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!
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
jorrell
jorrellOP9mo ago
ok
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
jorrell
jorrellOP9mo ago
however the buttons dont do anything when i click on one of them
d.js docs
d.js docs9mo ago
Suggestion for @jorrell: :guide: Creating Your Bot: Command handling read more
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
jorrell
jorrellOP9mo ago
yea
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
jorrell
jorrellOP9mo ago
alr hold on ima screenrecord from my iphone as i run the command
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
jorrell
jorrellOP9mo ago
ohhhhh right i forgot about that
d.js docs
d.js docs9mo ago
Suggestion for @jorrell: :guide: Message Components: Component interactions read more
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
jorrell
jorrellOP9mo ago
i did
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
jorrell
jorrellOP9mo ago
yea it works now
Want results from more Discord servers?
Add your server