#Wiktors help

1 messages ยท Page 1 of 1 (latest)

silent hawk
#

Hey Mushroom

#

๐Ÿ˜‚

vapid hinge
#

ok

silent hawk
#

Anyways

#

Let me send some inf

#

info

#

This is my bot.js

vapid hinge
#

yes

silent hawk
vapid hinge
#

any errors?

silent hawk
#

When I run my bot it says:

vapid hinge
#

show me line 14 of bot.js

silent hawk
#
(async () => {
    for (file of functions) {
        require(`./functions/${file}`)(client);
    }
})()```
vapid hinge
#

hmmm

#

spellings look correct

silent hawk
#

I'm new to js, and I want the slash commands working and it's just encounting errors all the time..

#

I've been doing this command handler for really long, around 4 hours and I can't get to the end of this..

#

I've been following yt tutorials

vapid hinge
#
(async () => {
    for (let i in functions) {
        require(`./functions/${functions[i]}`)(client);
    }
})()``` try this
vapid hinge
silent hawk
#
const {
    REST
} = require('@discord.js/rest');
const {
    Routes
} = require('discord-api-types/v9');
const fs = require('fs');
const clientId = '927300532635312158';
const guildId = '926897125529354281';

module.exports = (client) => {
        client.handleCommands = async (commandsFolders, path) => {
            client.commandArray = [];
            for (folder of commandFolders) {
                const commandFiles = fs.readdirSync(`${path}/${folder}`).filter(file => file.endsWith(".js"));
                for (const file of commandFiles) {
                    const command = require(`${path}/${folder}/${file}`);

                    client.commands.set(command.data.name, command);
                    client.commandArray.push(command.data.toJSON());

                }


            }

        }

        const rest = new REST({
            version: '9'
        }).setToken(OTI3MzAwNTMyNjM1MzEyMTU4.YdIN6w.UzNhr7btKODQv44uP_PCPfvq3uQ);

        (async () => {
                try {
                    console.log('Started refreshing application (/) commands.');

                    await rest.put(
                        Routes.applicationGuildCommands(clientId, guildId), {
                            body: client.commandArray
                        },
                    );

                    console.log('Successfully reloaded application (/) commands.');
                } catch (error) {
                    console.error(error);
                }
            });
        };``` 

this is the command handler
#

oh it has my token in there

#

i'll regenerate my token

vapid hinge
#

quick

#

I think people saw

untold wharf
# silent hawk

Can you console.log functions and show your 2 files in the functions folder

silent hawk
#

done

vapid hinge
silent hawk
#

Ok did that

vapid hinge
#

run it

silent hawk
#

still the same

vapid hinge
untold wharf
#

Yeah

silent hawk
#

alrighty and should i run the code again?

vapid hinge
#

yea

silent hawk
#

@vapid hinge @untold wharf

untold wharf
#

Does it log functions

silent hawk
#

Do you guys have any ready code for me to paste and see it

silent hawk
vapid hinge
silent hawk
#

@vapid hinge

vapid hinge
#

it is a variable, so did you declare it?

silent hawk
#

I don't think so

untold wharf
#

Wait a second

silent hawk
#
const Discord = require('discord.js');
const { Client, Intents, Collection} = require("discord.js");
const config = require("../config.json")
const fs = require(`fs`);
const bot = new Discord.Client({ intents: [Discord.Intents.FLAGS.GUILDS] })

bot.commands = new Collection();

const functions = fs.readdirSync(__dirname+ '/functions')
const eventFiles = fs.readdirSync(__dirname + "/events")
const commandFolders = fs.readdirSync(__dirname + "/commands") 
console.log(functions)

(async () => {
    for (let i in functions) {
        require(`./functions/${functions[i]}`)(client);
    }
})()

bot.handleEvents(eventFiles, "./src/events");
bot.handleCommands(commandFolders, "./src/commands")

bot.login(config.token);````
untold wharf
#

Add a semicolon after line 11 for a sec

silent hawk
#

That's my code

#

Done

untold wharf
#

Remove the console.log for a sec

vapid hinge
#

try this```js
jsconst Discord = require('discord.js');
const { Client, Intents, Collection} = require("discord.js");
const config = require("../config.json")
const fs = require(fs);
const bot = new Discord.Client({ intents: [Discord.Intents.FLAGS.GUILDS] })

bot.commands = new Collection();

const functions = fs.readdirSync('./functions')
const eventFiles = fs.readdirSync("./events")
const commandFolders = fs.readdirSync("./commands")
console.log(functions)

(async () => {
for (let i in functions) {
require(./functions/${functions[i]})(client);
}
})()

bot.handleEvents(eventFiles, "./src/events");
bot.handleCommands(commandFolders, "./src/commands")

bot.login(config.token);```

silent hawk
untold wharf
silent hawk
#

Removed and this is the error

untold wharf
#

Show scree

#

Screenshot*

silent hawk
untold wharf
#

Yes your bot doesn't have functions called handleEvents and handleCommands inside it

silent hawk
#

Hmm?

vapid hinge
#

are they in discord.js?

silent hawk
untold wharf
#

Yes those are in your functions folder, but not a property of your bot variable

vapid hinge
silent hawk
#
const {
    REST
} = require('@discord.js/rest');
const {
    Routes
} = require('discord-api-types/v9');
const fs = require('fs');
const clientId = '927300532635312158';
const guildId = '926897125529354281';

module.exports = (client) => {
        client.handleCommands = async (commandsFolders, path) => {
            client.commandArray = [];
            for (folder of commandFolders) {
                const commandFiles = fs.readdirSync(`${path}/${folder}`).filter(file => file.endsWith(".js"));
                for (const file of commandFiles) {
                    const command = require(`${path}/${folder}/${file}`);

                    client.commands.set(command.data.name, command);
                    client.commandArray.push(command.data.toJSON());

                }


            }

        }

        const rest = new REST({
            version: '9'
        }).setToken(token);

        (async () => {
                try {
                    console.log('Started refreshing application (/) commands.');

                    await rest.put(
                        Routes.applicationGuildCommands(clientId, guildId), {
                            body: client.commandArray
                        },
                    );

                    console.log('Successfully reloaded application (/) commands.');
                } catch (error) {
                    console.error(error);
                }
            });
        };```
#

thats the handlecommands file

silent hawk
#

And where

vapid hinge
#

do you know if they are in Discord JS?

untold wharf
#

You require() the function then call the function with client

vapid hinge
#

or you write your own

silent hawk
#

I'm new to JS and I don't know how to do it? How do I require the function

#

Like the cod

#

e

#

@untold wharf

vapid hinge
#

remove the bot. infront of them and at the top of the file put const { handleEvents, handleCommands } = require("discord.js") at the top

vapid hinge
#

bot.js

silent hawk
#

so instead of line 1 i put const { handleEvents, handleCommands } = require("discord.js")

vapid hinge
#

no, above like one

#

so at like one just press enter then it will make a new like

silent hawk
#

yeah

#

Like that

#

Yeah

#

And do I run the bot again? @vapid hinge

vapid hinge
#

yes

silent hawk
#

Now this is the error

vapid hinge
#

what tutorial did you use

#

cuz it's shit

silent hawk
#

A complete guide on How To Make Handlers for Slash Commands, Events, and Functions, for a Discord Bot in Discord.JS v13. This tutorial goes over how to make handlers, with explanation so new Discord.JS coders are able to learn!

Run this command to install the packages needed:
npm install @discordjs/rest discord-api-types @discordjs/builders

๐Ÿ”—...

โ–ถ Play video
vapid hinge
silent hawk
#

Oh alright..

#

I wasted half of my day ๐Ÿ˜‚

#

Anyways thanks for the help!!