Issue wth js

const { token } = require('./config.json');
const {Client, Events, GatewayIntentBits, SlashCommandBuilder, InteractionCallbackResponse } = require('discord.js')
const fs = require('node:fs')

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

client.commands = getCommands('./commands');

client.once(Events.ClientReady, (c) => {
console.log(`Logged in as ${c.user.tag}`);
});

client.on(Events.InteractionCreate, interaction => {
if(!interaction.isChatInputCommand()) return;

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

try{
if(interaction.replied) return;
command.execute(interaction);
} catch (error){
console.error(error);
}
});

client.login(token);




function getCommands(dir) {
let commands = new Collection();
const commandsFiles = getFiles(dir);

for(const commandFile of commandFiles) {
const command = require(commandFile);
commands.set(command.data.toJSON().name, command);
}
return commands;
}

function getFiles(dir) {
const files = fs.readdirStync(dir, {
withFileTypes: true
});
let commandFiles = [];

for(const files of files) {
if(file.isDirectory()){
commandFiles = [
...commandFiles,
...getFiles('${dir}/${file.name}'),
]
} else if (file.name.endsWith(".js")) {
commandFiles.push(`${dir}/${file.name}`);
}
}
return commandFiles}
const { token } = require('./config.json');
const {Client, Events, GatewayIntentBits, SlashCommandBuilder, InteractionCallbackResponse } = require('discord.js')
const fs = require('node:fs')

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

client.commands = getCommands('./commands');

client.once(Events.ClientReady, (c) => {
console.log(`Logged in as ${c.user.tag}`);
});

client.on(Events.InteractionCreate, interaction => {
if(!interaction.isChatInputCommand()) return;

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

try{
if(interaction.replied) return;
command.execute(interaction);
} catch (error){
console.error(error);
}
});

client.login(token);




function getCommands(dir) {
let commands = new Collection();
const commandsFiles = getFiles(dir);

for(const commandFile of commandFiles) {
const command = require(commandFile);
commands.set(command.data.toJSON().name, command);
}
return commands;
}

function getFiles(dir) {
const files = fs.readdirStync(dir, {
withFileTypes: true
});
let commandFiles = [];

for(const files of files) {
if(file.isDirectory()){
commandFiles = [
...commandFiles,
...getFiles('${dir}/${file.name}'),
]
} else if (file.name.endsWith(".js")) {
commandFiles.push(`${dir}/${file.name}`);
}
}
return commandFiles}
23 Replies
d.js toolkit
d.js toolkit•3w ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Jacob
JacobOP•3w ago
No description
Jacob
JacobOP•3w ago
Hey just started working on bots today still learning, I'm coming across this error and I don't know how to fix it or where to declare Collection up with Client, Events, and such
Unknown User
Unknown User•3w ago
Message Not Public
Sign In & Join Server To View
Jacob
JacobOP•3w ago
How 😭
Unknown User
Unknown User•3w ago
Message Not Public
Sign In & Join Server To View
Jacob
JacobOP•3w ago
sorry u are talking Japanese to me rn LOL
Unknown User
Unknown User•3w ago
Message Not Public
Sign In & Join Server To View
Jacob
JacobOP•3w ago
sorry, are u able to help me with what code to put? If not ig i need to leave the server until im more familiar w it..
Unknown User
Unknown User•3w ago
Message Not Public
Sign In & Join Server To View
Jacob
JacobOP•3w ago
just started today
Unknown User
Unknown User•3w ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs•3w ago
:guide: Home: Introduction - Before you begin... read more
Jacob
JacobOP•3w ago
I'm watching a youtube video and reading the doc
Unknown User
Unknown User•3w ago
Message Not Public
Sign In & Join Server To View
Jacob
JacobOP•3w ago
No description
Unknown User
Unknown User•3w ago
Message Not Public
Sign In & Join Server To View
Jacob
JacobOP•3w ago
ok
Unknown User
Unknown User•3w ago
Message Not Public
Sign In & Join Server To View
Jacob
JacobOP•3w ago
ill read it over again thx
Jacob
JacobOP•3w ago
I fixed it, you couldve just told me to add it to line 2
No description
Jacob
JacobOP•3w ago
all i was missin
Unknown User
Unknown User•3w ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?