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],
});
},
};interactionCreate:
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);
}
}
},
};