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 toolkit2y 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
MarcusOP2y ago
I hope someone soon will help me out!
SpecialSauce
SpecialSauce2y ago
How is your file directory structured? Does it match the code looking for subdirectories?
Marcus
MarcusOP2y ago
Uhmm, it might.
SpecialSauce
SpecialSauce2y ago
Show command folder structure
Marcus
MarcusOP2y ago
SpecialSauce
SpecialSauce2y ago
Yeah that’s the issue. It’s looking for folders in the command folder and finds a file.
Marcus
MarcusOP2y ago
wut?
SpecialSauce
SpecialSauce2y ago
It’s looking for this commands/folder/ping.js
Marcus
MarcusOP2y ago
Waaaait, why that?
SpecialSauce
SpecialSauce2y ago
So either change the code or add the sub folders
Marcus
MarcusOP2y ago
where does it look for the ping? and how can I fix the code?
SpecialSauce
SpecialSauce2y ago
Ping is just the example In your case it would be test.js
Marcus
MarcusOP2y ago
yep but how would I fix that?
SpecialSauce
SpecialSauce2y ago
^
Marcus
MarcusOP2y 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
SpecialSauce2y 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
MarcusOP2y ago
Do I have to call the folders something specific? Cuz now it just came up with this
Marcus
MarcusOP2y ago
Marcus
MarcusOP2y ago
SpecialSauce
SpecialSauce2y ago
Can’t have uppercase letters in command name
Marcus
MarcusOP2y ago
then I am good right but it still comes with the error
SpecialSauce
SpecialSauce2y ago
Test.js line 5
Marcus
MarcusOP2y ago
Ohh, haha thanks! Its working, but I got this one?
Marcus
MarcusOP2y ago
SpecialSauce
SpecialSauce2y ago
Show where you declare rest
d.js docs
d.js docs2y ago
guide Creating Your Bot: Command registration - Guild commands read more
SpecialSauce
SpecialSauce2y ago
Should look like line 18 If it does then token might be undefined
Marcus
MarcusOP2y ago
I think I got it. but now it gives me this whenever I use the command
Marcus
MarcusOP2y ago
Marcus
MarcusOP2y 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
SpecialSauce2y ago
You probably reply or defer in your handler
Marcus
MarcusOP2y ago
ehhh? what
d.js docs
d.js docs2y 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
MarcusOP2y ago
I haven't replied already. I only use 1 interaction.reply
SpecialSauce
SpecialSauce2y ago
Show your interaction handler
Marcus
MarcusOP2y ago
interaction handler? This is everything I have
Marcus
MarcusOP2y ago
SpecialSauce
SpecialSauce2y ago
InteractionCreate.js
Marcus
MarcusOP2y 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
SpecialSauce2y ago
Hmm not seeing anything off there. Show index
Marcus
MarcusOP2y 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
SpecialSauce2y ago
Ok if that’s everything it might be in handelEvents.js
Marcus
MarcusOP2y 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
SpecialSauce2y ago
And your bot doesn’t reply with anything at all?
Marcus
MarcusOP2y ago
no
SpecialSauce
SpecialSauce2y ago
What’s hx.js ?
Marcus
MarcusOP2y 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
SpecialSauce2y ago
You’re logging in twice
Marcus
MarcusOP2y ago
Waaait is that why?
SpecialSauce
SpecialSauce2y ago
High possibility
Marcus
MarcusOP2y 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
SpecialSauce2y ago
You could listen the the MessageDelete event. And resend if it’s passed the message with the embed.
Marcus
MarcusOP2y ago
but what about the thing with just making it send it one time?
SpecialSauce
SpecialSauce2y ago
What do you mean?
Marcus
MarcusOP2y ago
like the bot needs to send a embed 1 time like without me having to do anything
SpecialSauce
SpecialSauce2y 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
MarcusOP2y ago
Yeah, because I cant make it when it logs in, because then it would just send it multiple times.
Want results from more Discord servers?
Add your server