Registering commands

I need help with making the commands register
66 Replies
d.js toolkit
d.js toolkit2y 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!
d.js docs
d.js docs2y ago
Suggestion for @hpmi5:guide Creating Your Bot: Registering slash commands read more
hpmi5
hpmi5OP2y ago
How do I fix this?
No description
Elk
Elk2y ago
show code
DANIEL
DANIEL2y ago
should be name: with : not ,
hpmi5
hpmi5OP2y ago
No description
hpmi5
hpmi5OP2y ago
here yep commonJS i think sure
hpmi5
hpmi5OP2y ago
did i do it right?
No description
hpmi5
hpmi5OP2y ago
here is what it said
No description
hpmi5
hpmi5OP2y ago
this error
No description
hpmi5
hpmi5OP2y ago
oh ok
hpmi5
hpmi5OP2y ago
i moved it up
No description
hpmi5
hpmi5OP2y ago
any idea whats wrong? do you want me to do node -v?
hpmi5
hpmi5OP2y ago
No description
d.js docs
d.js docs2y ago
To share long code snippets use a service like gist, sourcebin, starbin, or similar instead of posting them as large code blocks.
hpmi5
hpmi5OP2y ago
const { REST, Routes } = require('discord.js');
const { clientId, guildId, token } = require(`./Config.json`);
const fs = require('node:fs');
const path = require('node:path');
const Lockdown = require('./commands/Lockdown');
const Server = require('./commands/Server');
const { setUncaughtExceptionCaptureCallback } = require('node:process');

console.log(__dirname)

const commands = [];
// Grab all the command files from the commands directory you created earlier
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);
for (const folder of commandFolders) {
// Grab all the command files from the commands directory you created earlier
const commandsPath = path.join(foldersPath, commands);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}

// Construct and prepare an instance of the REST module
const rest = new REST().setToken(token);

// and deploy your commands!
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);

// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();
const { REST, Routes } = require('discord.js');
const { clientId, guildId, token } = require(`./Config.json`);
const fs = require('node:fs');
const path = require('node:path');
const Lockdown = require('./commands/Lockdown');
const Server = require('./commands/Server');
const { setUncaughtExceptionCaptureCallback } = require('node:process');

console.log(__dirname)

const commands = [];
// Grab all the command files from the commands directory you created earlier
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);
for (const folder of commandFolders) {
// Grab all the command files from the commands directory you created earlier
const commandsPath = path.join(foldersPath, commands);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}

// Construct and prepare an instance of the REST module
const rest = new REST().setToken(token);

// and deploy your commands!
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);

// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();
hpmi5
hpmi5OP2y ago
No description
hpmi5
hpmi5OP2y ago
idk
hpmi5
hpmi5OP2y ago
i retyped it and this happend
No description
No description
hpmi5
hpmi5OP2y ago
what if i do this
No description
hpmi5
hpmi5OP2y ago
its an object maybe thats why?
No description
hpmi5
hpmi5OP2y ago
oh how will i fix the node installation? reinstall it? i havnt tried them i will soon i just gotta do something else first
wert
wert2y ago
I'm experiencing the same issues with the boiler plate code in the guide on discord.js. Cannot get basic ping command to register using guide documentation or general discord.js documentation.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP2y ago
path.join is a function
hpmi5
hpmi5OP2y ago
No description
hpmi5
hpmi5OP2y ago
dirname didnt work tho
No description
hpmi5
hpmi5OP2y ago
is this better?
No description
hpmi5
hpmi5OP2y ago
this better?
No description
hpmi5
hpmi5OP2y ago
it is a string?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP2y ago
simple confused
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP2y ago
ok so im not meant to have commands
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP2y ago
i have all the files i need so can i just delete that bit
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP2y ago
do i delete those lines cuse i got all i need?
No description
No description
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP2y ago
no the first pic
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP2y ago
i know but do i still need those lines?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP2y ago
any way i fixed line 17
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP2y ago
oh ok
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP2y ago
ye but i grabed all those files already so i dont need
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP2y ago
No description
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP2y ago
ye i know but having this connstantly imports it form commands right?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP2y ago
ok
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP2y ago
No description
hpmi5
hpmi5OP2y ago
new problem
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP2y ago
__dirname?
hpmi5
hpmi5OP2y ago
No description
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP2y ago
dirname = directory name const = constant?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP2y ago
ok i watch like 3 hours of random coding and learned nothing
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP2y ago
ok thanks it was line 14 do you have anything you recommend I need to know because the 3 hour video only taught me what a string and stuff is and how to make a null or something

Did you find this page helpful?