My SlashCommandHandler isn't working..

No clue how to fix it..
const { Client, Collection, Events, EmbedBuilder, PermissionsBitField, Permissions, MessageManager, Embed } = require("discord.js");
const client = new Client({ intents: ["Guilds"] });
const fs = require('fs');

client.commands = new Collection();

client.config = require("./config.json");

const functions = fs.readdirSync("./functions").filter(file => file.endsWith(".js"));
const eventFiles = fs.readdirSync("./events").filter(file => file.endsWith(".js"));
const commandFolders = fs.readdirSync("./commands");

(async () => {
for (file of functions) {
require(`./functions/${file}`)(client);
}
client.handleEvents(eventFiles, "./events");
client.handleCommands(commandFolders, "./commands");
client.login(client.config.token)
})();


client
.login(client.config.token)
.then(() => {
console.log(`Cliend logged in as ${client.user.username}`)
client.user.setActivity(`Support`)
})
const { Client, Collection, Events, EmbedBuilder, PermissionsBitField, Permissions, MessageManager, Embed } = require("discord.js");
const client = new Client({ intents: ["Guilds"] });
const fs = require('fs');

client.commands = new Collection();

client.config = require("./config.json");

const functions = fs.readdirSync("./functions").filter(file => file.endsWith(".js"));
const eventFiles = fs.readdirSync("./events").filter(file => file.endsWith(".js"));
const commandFolders = fs.readdirSync("./commands");

(async () => {
for (file of functions) {
require(`./functions/${file}`)(client);
}
client.handleEvents(eventFiles, "./events");
client.handleCommands(commandFolders, "./commands");
client.login(client.config.token)
})();


client
.login(client.config.token)
.then(() => {
console.log(`Cliend logged in as ${client.user.username}`)
client.user.setActivity(`Support`)
})
- Index file https://media.discordapp.net/attachments/1091664900906025100/1091664901094772826/image.png
58 Replies
d.js toolkit
d.js toolkit15mo ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Marcus
Marcus15mo ago
I hope someone soon will help me out!
SpecialSauce
SpecialSauce15mo ago
How is your file directory structured? Does it match the code looking for subdirectories?
Marcus
Marcus15mo ago
Uhmm, it might.
SpecialSauce
SpecialSauce15mo ago
Show command folder structure
Marcus
Marcus15mo ago
SpecialSauce
SpecialSauce15mo ago
Yeah that’s the issue. It’s looking for folders in the command folder and finds a file.
Marcus
Marcus15mo ago
wut?
SpecialSauce
SpecialSauce15mo ago
It’s looking for this commands/folder/ping.js
Marcus
Marcus15mo ago
Waaaait, why that?
SpecialSauce
SpecialSauce15mo ago
So either change the code or add the sub folders
Marcus
Marcus15mo ago
where does it look for the ping? and how can I fix the code?
SpecialSauce
SpecialSauce15mo ago
Ping is just the example In your case it would be test.js
Marcus
Marcus15mo ago
yep but how would I fix that?
SpecialSauce
SpecialSauce15mo ago
^
Marcus
Marcus15mo ago
Like what do I have to change I know, it just sounds like I want spoon feeding, but I dont really understand.. So thats why I am asking a little bit deeper.
SpecialSauce
SpecialSauce15mo ago
If you want to just have the commands in your command folder you need to modify the part where it reads 'commandFolders' as these are files, not folders the way you have it set up. Or, you could just create the sub folders in the command folder and not touch the code
Marcus
Marcus15mo ago
Do I have to call the folders something specific? Cuz now it just came up with this
Marcus
Marcus15mo ago
Marcus
Marcus15mo ago
SpecialSauce
SpecialSauce15mo ago
Can’t have uppercase letters in command name
Marcus
Marcus15mo ago
then I am good right but it still comes with the error
SpecialSauce
SpecialSauce15mo ago
Test.js line 5
Marcus
Marcus15mo ago
Ohh, haha thanks! Its working, but I got this one?
Marcus
Marcus15mo ago
SpecialSauce
SpecialSauce15mo ago
Show where you declare rest
d.js docs
d.js docs15mo ago
guide Creating Your Bot: Command registration - Guild commands read more
SpecialSauce
SpecialSauce15mo ago
Should look like line 18 If it does then token might be undefined
Marcus
Marcus15mo ago
I think I got it. but now it gives me this whenever I use the command
Marcus
Marcus15mo ago
Marcus
Marcus15mo ago
const { SlashCommandBuilder } = require('@discordjs/builders');

const { EmbedBuilder, message } = require('discord.js')


const faqEmbed = new EmbedBuilder()
.setColor('Aqua')
.setTitle('**Swapit - FAQ**')
.setURL('https://discord.gg/pRVfBjxX3A')
.setAuthor({ name: 'Swapit @ 2023', iconURL: 'https://i.imgur.com/AfFp7pu.png', url: 'https://discord.gg/pRVfBjxX3A' })
.setTimestamp()
.setFooter({ text: 'Swapit @ 2023', iconURL: 'https://discord.gg/pRVfBjxX3A' })




module.exports = {
data: new SlashCommandBuilder()
.setName('faq')
.setDescription('Useful information about Swapit'),
async execute(interaction, client) {
interaction.reply({ embeds: [faqEmbed], ephemeral: true });
}
}
const { SlashCommandBuilder } = require('@discordjs/builders');

const { EmbedBuilder, message } = require('discord.js')


const faqEmbed = new EmbedBuilder()
.setColor('Aqua')
.setTitle('**Swapit - FAQ**')
.setURL('https://discord.gg/pRVfBjxX3A')
.setAuthor({ name: 'Swapit @ 2023', iconURL: 'https://i.imgur.com/AfFp7pu.png', url: 'https://discord.gg/pRVfBjxX3A' })
.setTimestamp()
.setFooter({ text: 'Swapit @ 2023', iconURL: 'https://discord.gg/pRVfBjxX3A' })




module.exports = {
data: new SlashCommandBuilder()
.setName('faq')
.setDescription('Useful information about Swapit'),
async execute(interaction, client) {
interaction.reply({ embeds: [faqEmbed], ephemeral: true });
}
}
SpecialSauce
SpecialSauce15mo ago
You probably reply or defer in your handler
Marcus
Marcus15mo ago
ehhh? what
d.js docs
d.js docs15mo ago
DiscordAPIError: Interaction has already been acknowledged[InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred. You have already replied to the interaction. • Use <Interaction>.followUp() to send a new message • If you deferred reply it's better to use <Interaction>.editReply() • Responding to slash commands / buttons / select menus
Marcus
Marcus15mo ago
I haven't replied already. I only use 1 interaction.reply
SpecialSauce
SpecialSauce15mo ago
Show your interaction handler
Marcus
Marcus15mo ago
interaction handler? This is everything I have
Marcus
Marcus15mo ago
SpecialSauce
SpecialSauce15mo ago
InteractionCreate.js
Marcus
Marcus15mo ago
const { Interaction } = require("discord.js");

module.exports = {
name: 'interactionCreate',
async execute(interaction, client) {
if (!interaction.isCommand()) return;

const command = client.commands.get(interaction.commandName);

if (!command) return

try{


await command.execute(interaction, client);
} catch (error) {
console.log(error);
await interaction.reply({
content: 'There was an error while executing this command!',
ephemeral: true
});
}

},



};
const { Interaction } = require("discord.js");

module.exports = {
name: 'interactionCreate',
async execute(interaction, client) {
if (!interaction.isCommand()) return;

const command = client.commands.get(interaction.commandName);

if (!command) return

try{


await command.execute(interaction, client);
} catch (error) {
console.log(error);
await interaction.reply({
content: 'There was an error while executing this command!',
ephemeral: true
});
}

},



};
SpecialSauce
SpecialSauce15mo ago
Hmm not seeing anything off there. Show index
Marcus
Marcus15mo ago
const { Client, Collection, Events, EmbedBuilder, PermissionsBitField, Permissions, MessageManager, Embed } = require("discord.js");
const client = new Client({ intents: ["Guilds"] });
const fs = require('fs');

client.commands = new Collection();

client.config = require("./config.json");

const functions = fs.readdirSync("./functions").filter(file => file.endsWith(".js"));
const eventFiles = fs.readdirSync("./events").filter(file => file.endsWith(".js"));
const commandFolders = fs.readdirSync("./commands");

(async () => {
for (file of functions) {
require(`./functions/${file}`)(client);
}
client.handleEvents(eventFiles, "./events");
client.handleCommands(commandFolders, "./commands");
client.login(client.config.token)
})();


client
.login(client.config.token)
.then(() => {
console.log(`Cliend logged in as ${client.user.username}`)
client.user.setActivity(`Support`)
})
const { Client, Collection, Events, EmbedBuilder, PermissionsBitField, Permissions, MessageManager, Embed } = require("discord.js");
const client = new Client({ intents: ["Guilds"] });
const fs = require('fs');

client.commands = new Collection();

client.config = require("./config.json");

const functions = fs.readdirSync("./functions").filter(file => file.endsWith(".js"));
const eventFiles = fs.readdirSync("./events").filter(file => file.endsWith(".js"));
const commandFolders = fs.readdirSync("./commands");

(async () => {
for (file of functions) {
require(`./functions/${file}`)(client);
}
client.handleEvents(eventFiles, "./events");
client.handleCommands(commandFolders, "./commands");
client.login(client.config.token)
})();


client
.login(client.config.token)
.then(() => {
console.log(`Cliend logged in as ${client.user.username}`)
client.user.setActivity(`Support`)
})
SpecialSauce
SpecialSauce15mo ago
Ok if that’s everything it might be in handelEvents.js
Marcus
Marcus15mo ago
module.exports = (client) => {
client.handleEvents = async (eventFiles, path) => {
for (const file of eventFiles) {
const event = require(`../events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args, client));
} else {
client.on(event.name, (...args) => event.execute(...args, client));
}
}
};
}
module.exports = (client) => {
client.handleEvents = async (eventFiles, path) => {
for (const file of eventFiles) {
const event = require(`../events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args, client));
} else {
client.on(event.name, (...args) => event.execute(...args, client));
}
}
};
}
SpecialSauce
SpecialSauce15mo ago
And your bot doesn’t reply with anything at all?
Marcus
Marcus15mo ago
no
SpecialSauce
SpecialSauce15mo ago
What’s hx.js ?
Marcus
Marcus15mo ago
just a slash command I can send it for you
const { SlashCommandBuilder } = require('@discordjs/builders');

module.exports = {
data: new SlashCommandBuilder()
.setName('est')
.setDescription('Test2'),
async execute(interaction, client) {
interaction.reply({ content: 'The bot is working' });
}
}
const { SlashCommandBuilder } = require('@discordjs/builders');

module.exports = {
data: new SlashCommandBuilder()
.setName('est')
.setDescription('Test2'),
async execute(interaction, client) {
interaction.reply({ content: 'The bot is working' });
}
}
SpecialSauce
SpecialSauce15mo ago
You’re logging in twice
Marcus
Marcus15mo ago
Waaait is that why?
SpecialSauce
SpecialSauce15mo ago
High possibility
Marcus
Marcus15mo ago
@specialsauce how can I make my bot send 1 embed in a channel, and if the embed gets deleted it sends the embed again, and it can't send the embed multiple times.
SpecialSauce
SpecialSauce15mo ago
You could listen the the MessageDelete event. And resend if it’s passed the message with the embed.
Marcus
Marcus15mo ago
but what about the thing with just making it send it one time?
SpecialSauce
SpecialSauce15mo ago
What do you mean?
Marcus
Marcus15mo ago
like the bot needs to send a embed 1 time like without me having to do anything
SpecialSauce
SpecialSauce15mo ago
Well you would need to do something to trigger the initial message I’ve seen commands that send the initial message for reactions
Marcus
Marcus15mo ago
Yeah, because I cant make it when it logs in, because then it would just send it multiple times.