#My SlashCommandHandler isn't working..

77 messages · Page 1 of 1 (latest)

wary fjord
#

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`)
    })
``` - Index file

https://media.discordapp.net/attachments/1091664900906025100/1091664901094772826/image.png
distant basaltBOT
#

• 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.

wary fjord
#

I hope someone soon will help me out!

frank stirrup
wary fjord
#

Uhmm, it might.

frank stirrup
wary fjord
frank stirrup
# wary fjord

Yeah that’s the issue. It’s looking for folders in the command folder and finds a file.

wary fjord
#

wut?

frank stirrup
#

It’s looking for this
commands/folder/ping.js

wary fjord
#

Waaaait, why that?

frank stirrup
#

So either change the code or add the sub folders

wary fjord
#

where does it look for the ping?

#

and how can I fix the code?

frank stirrup
wary fjord
#

yep

#

but how would I fix that?

wary fjord
#

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.

frank stirrup
#

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

wary fjord
#

Do I have to call the folders something specific?

#

Cuz now it just came up with this

frank stirrup
wary fjord
#

then I am good

#

right

#

but it still comes with the error

frank stirrup
wary fjord
#

Ohh, haha thanks!

#

Its working, but I got this one?

frank stirrup
#

Show where you declare rest

short roverBOT
#

guide Creating Your Bot: Command registration - Guild commands
read more

frank stirrup
#

Should look like line 18

#

If it does then token might be undefined

wary fjord
#

I think I got it.

#

but now it gives me this whenever I use the command

#
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 });
    }
}




frank stirrup
#

You probably reply or defer in your handler

wary fjord
#

ehhh?

#

what

short roverBOT
#

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

wary fjord
#

I haven't replied already.

#

I only use 1 interaction.reply

frank stirrup
wary fjord
#

interaction handler?

#

This is everything I have

frank stirrup
#

InteractionCreate.js

wary fjord
#
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
            });
        } 

    },
    


};
frank stirrup
#

Hmm not seeing anything off there.

#

Show index

wary fjord
# frank stirrup Show index
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`)
    })
frank stirrup
wary fjord
# frank stirrup Ok if that’s everything it might be in handelEvents.js
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));
            }
        }
    };
}
frank stirrup
#

And your bot doesn’t reply with anything at all?

wary fjord
#

no

frank stirrup
#

What’s hx.js ?

wary fjord
#

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' });
    }
}
wary fjord
#

Waaait

#

is that why?

frank stirrup
#

High possibility

wary fjord
#

@frank stirrup 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.

frank stirrup
wary fjord
#

but what about the thing with just making it send it one time?

frank stirrup
wary fjord
#

like the bot needs to send a embed 1 time

#

like without me having to do anything

frank stirrup
#

Well you would need to do something to trigger the initial message

#

I’ve seen commands that send the initial message for reactions