#thread
1 messages · Page 1 of 1 (latest)
the sm is annoying help here?
ok so i logged (button)
ButtonBuilder {
data: {
type: 2,
emoji: undefined,
custom_id: 'srules',
label: 'Server Rules',
style: 2
}
}
this is wht i got
send full error and code(full) again
its ok, you can send it using services like sourcebin
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require("discord.js");
const { execute } = require("../server/donate");
module.exports = {
data: new SlashCommandBuilder()
.setName('rules')
.setDescription('View the rules of the server or bot')
.addSubcommand(subcommand =>
subcommand
.setName('server')
.setDescription('View the rules of the server'))
.addSubcommand(subcommand =>
subcommand
.setName('bot')
.setDescription('View the rules of the bot!')),
/**
*
* @param {Client} client
* @param {ChatInputCommandInteraction} interaction
*/
async execute(client, interaction, args) {
const button = new ButtonBuilder()
.setCustomId('srules')
.setLabel('Server Rules')
.setStyle(ButtonStyle.Secondary)
if (interaction.commandName === 'rules') {
if (interaction.options.getSubcommand() === 'server') {
const sembed = new EmbedBuilder()
.setColor("Random")
.setTitle(" RULES ")
.setDescription("Breaking these rules leaves you subject to punishment by the staff members. Follow them and we wont have a problem, but don't and we will most likely have an issue. These rules are subject to change at anytime for any reason.")
.setAuthor({ name: `${interaction.guild.name}`, iconURL: interaction.guild.iconURL({dynamic : true}), url: 'https://discord.gg/gUwCbqpYjz' })
.setFooter({ text: "Breaking any of these rules are punishable depending the offense.", iconURL: interaction.guild.iconURL({dynamic : true}) })
await interaction.reply({ components: [new ActionRowBuilder().addComponents(button)], embeds: [sembed], ephemeral: true })
console.log(button)
} // Server rules ends here.
}
}
}```
components/buttons/rules.js - js module.exports = { data: { name: `srules` }, async execute(interaction, client) { await interaction.reply({ content: `Hello!` }); } }
handlers/loadcomponents.js -
const { readdirSync, read } = require('fs');
module.exports = (client) => {
client.handleComponents = async () => {
const componentFolders = readdirSync(`../Components`);
for (const folder of componentFolders) {
const componentFiles = readdirSync(`../Components/${folder}`).filter(
(file) => file.endsWith('.js')
);
const { buttons } = client;
switch (folder) {
case "buttons":
for (const file of componentFiles) {
const button = require(`../Components/${folder}/${file}`);
buttons.set(button.data.name, button);
}
break;
default:
break;
}
}
};
};```
it occurs when subcommand is server?
??
oh yeah
so it console logs but doesn't reply?
yeah
no, in discord
wait so error comes not from slash command but from button?
yeah
how are you handling for button interaction create
else if (interaction.isButton()) {
const { buttons } = client;
const { customId } = interaction;
const button = buttons.get(customId);
if (!button) return new Error('There is no code for this button!');
try {
await button.execute(interaction, client);
} catch (err) {
console.error(err);
}```
whole code -
const { Client } = require("discord.js");
const color = require("colors");
module.exports = {
name: "interactionCreate",
/**
*
* @param {ChatInput} interaction
* @param {Client} client
*/
async execute(interaction, client) {
if (interaction.isChatInputCommand()) {
if (interaction.user.bot) return;
const command = client.slashCommands.get(interaction.commandName);
if (!command) {
interaction.reply({
ephemeral: true,
content: "This command is outdated!"
});
};
try {
command.execute(client, interaction);
} catch (error) {
console.log(`${color.bold.red(`[INTERACTION > CREATE : ERROR]`)} ` + `${error}`.bgRed);
}
} else if (interaction.isButton()) {
const { buttons } = client;
const { customId } = interaction;
const button = buttons.get(customId);
if (!button) return new Error('There is no code for this button!');
try {
await button.execute(interaction, client);
} catch (err) {
console.error(err);
}
}
}
};```
log button before if(!button)
undefined
where are you running this function
it looks like you didn't execute it