Registering commands

I need help with making the commands register
66 Replies
d.js toolkit
d.js toolkit16mo 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 docs16mo ago
Suggestion for @hpmi5:guide Creating Your Bot: Registering slash commands read more
hpmi5
hpmi5OP16mo ago
How do I fix this?
No description
Elk
Elk16mo ago
show code
DANIEL
DANIEL16mo ago
should be name: with : not ,
hpmi5
hpmi5OP16mo ago
No description
hpmi5
hpmi5OP16mo ago
here yep commonJS i think sure
hpmi5
hpmi5OP16mo ago
did i do it right?
No description
hpmi5
hpmi5OP16mo ago
here is what it said
No description
hpmi5
hpmi5OP16mo ago
this error
No description
hpmi5
hpmi5OP16mo ago
oh ok
hpmi5
hpmi5OP16mo ago
i moved it up
No description
hpmi5
hpmi5OP16mo ago
any idea whats wrong? do you want me to do node -v?
hpmi5
hpmi5OP16mo ago
No description
d.js docs
d.js docs16mo ago
To share long code snippets use a service like gist, sourcebin, starbin, or similar instead of posting them as large code blocks.
hpmi5
hpmi5OP16mo 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
hpmi5OP16mo ago
No description
hpmi5
hpmi5OP16mo ago
idk
hpmi5
hpmi5OP16mo ago
i retyped it and this happend
No description
No description
hpmi5
hpmi5OP16mo ago
what if i do this
No description
hpmi5
hpmi5OP16mo ago
its an object maybe thats why?
No description
hpmi5
hpmi5OP16mo 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
wert16mo 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 User16mo ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP16mo ago
path.join is a function
hpmi5
hpmi5OP16mo ago
No description
hpmi5
hpmi5OP16mo ago
dirname didnt work tho
No description
hpmi5
hpmi5OP16mo ago
is this better?
No description
hpmi5
hpmi5OP16mo ago
this better?
No description
hpmi5
hpmi5OP16mo ago
it is a string?
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP16mo ago
simple confused
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP16mo ago
ok so im not meant to have commands
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP16mo ago
i have all the files i need so can i just delete that bit
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP16mo ago
do i delete those lines cuse i got all i need?
No description
No description
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP16mo ago
no the first pic
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP16mo ago
i know but do i still need those lines?
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP16mo ago
any way i fixed line 17
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP16mo ago
oh ok
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP16mo ago
ye but i grabed all those files already so i dont need
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP16mo ago
No description
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP16mo ago
ye i know but having this connstantly imports it form commands right?
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP16mo ago
ok
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP16mo ago
No description
hpmi5
hpmi5OP16mo ago
new problem
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP16mo ago
__dirname?
hpmi5
hpmi5OP16mo ago
No description
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP16mo ago
dirname = directory name const = constant?
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP16mo ago
ok i watch like 3 hours of random coding and learned nothing
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
hpmi5
hpmi5OP16mo 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
Want results from more Discord servers?
Add your server