jorrell
DIAdiscord.js - Imagine an app
•Created by jorrell on 4/21/2024 in #djs-questions
error shows that No command matching ban was found.
ban.js:
interactionCreate:
const { ActionRowBuilder, ButtonBuilder, ButtonStyle, SlashCommandBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('ban')
.setDescription('Bans a user from the server.')
.addUserOption(option => option
.setName('target')
.setDescription('The user to ban')
.setRequired(true)
)
.addStringOption(option => option
.setName('reason')
.setDescription('The reason for the ban')
.setRequired(false)
),
async execute(interaction) {
const target = interaction.options.getUser('target');
const reason = interaction.options.getString('reason') ?? 'No reason provided';
const confirm = new ButtonBuilder()
.setCustomId('confirm')
.setLabel('Confirm Ban')
.setStyle(ButtonStyle.Danger);
const cancel = new ButtonBuilder()
.setCustomId('cancel')
.setLabel('Cancel')
.setStyle(ButtonStyle.Secondary);
const row = new ActionRowBuilder()
.addComponents(cancel, confirm);
await interaction.reply({
content: `Are you sure you want to ban ${target} for reason: ${reason}?`,
components: [row],
});
},
};
const { ActionRowBuilder, ButtonBuilder, ButtonStyle, SlashCommandBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('ban')
.setDescription('Bans a user from the server.')
.addUserOption(option => option
.setName('target')
.setDescription('The user to ban')
.setRequired(true)
)
.addStringOption(option => option
.setName('reason')
.setDescription('The reason for the ban')
.setRequired(false)
),
async execute(interaction) {
const target = interaction.options.getUser('target');
const reason = interaction.options.getString('reason') ?? 'No reason provided';
const confirm = new ButtonBuilder()
.setCustomId('confirm')
.setLabel('Confirm Ban')
.setStyle(ButtonStyle.Danger);
const cancel = new ButtonBuilder()
.setCustomId('cancel')
.setLabel('Cancel')
.setStyle(ButtonStyle.Secondary);
const row = new ActionRowBuilder()
.addComponents(cancel, confirm);
await interaction.reply({
content: `Are you sure you want to ban ${target} for reason: ${reason}?`,
components: [row],
});
},
};
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.`
);
return;
}
try {
await command.execute(interaction);
} catch (error) {
console.error(`Error executing ${interaction.commandName}`);
console.error(error);
}
}
if (interaction.isButton()) {
const button = interaction.client.buttons.get(interaction.customId);
if (!button) {
console.error(`No button matching ${interaction.customId} was found.`);
return;
}
try {
await button.execute(interaction);
} catch (error) {
console.error(
`Error executing button interaction with customId: ${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.`
);
return;
}
try {
await selectMenu.execute(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.`
);
return;
}
try {
await command.execute(interaction);
} catch (error) {
console.error(`Error executing ${interaction.commandName}`);
console.error(error);
}
}
if (interaction.isButton()) {
const button = interaction.client.buttons.get(interaction.customId);
if (!button) {
console.error(`No button matching ${interaction.customId} was found.`);
return;
}
try {
await button.execute(interaction);
} catch (error) {
console.error(
`Error executing button interaction with customId: ${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.`
);
return;
}
try {
await selectMenu.execute(interaction);
} catch (error) {
console.error(`Error executing ${interaction.customId}`);
console.error(error);
}
}
},
};
79 replies
DIAdiscord.js - Imagine an app
•Created by jorrell on 4/14/2024 in #djs-questions
Interaction Create and Button Error
Terminal:
InteractionCreate.js:
buttons.js:
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)
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);
}
}
},
};
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] });
}
}
23 replies
DIAdiscord.js - Imagine an app
•Created by jorrell on 4/10/2023 in #djs-questions
bot doesnt send anything when i send a command
28 replies