trying to load slash commands

deployCommandsF()
^

TypeError: deployCommandsF is not a function
at Object.<anonymous> (C:\Users\clou1\OneDrive\Desktop\atom bot\index.js:8:1)
at Module._compile (node:internal/modules/cjs/loader:1378:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1437:10)
at Module.load (node:internal/modules/cjs/loader:1212:32)
at Module._load (node:internal/modules/cjs/loader:1028:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:142:12)
at node:internal/main/run_main_module:28:49

Node.js v21.6.2
PS C:\Users\clou1\OneDrive\Desktop\atom bot> node .
C:\Users\clou1\OneDrive\Desktop\atom bot\index.js:8
deployCommandsF()
^

TypeError: deployCommandsF is not a function
at Object.<anonymous> (C:\Users\clou1\OneDrive\Desktop\atom bot\index.js:8:1)
at Module._compile (node:internal/modules/cjs/loader:1378:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1437:10)
at Module.load (node:internal/modules/cjs/loader:1212:32)
at Module._load (node:internal/modules/cjs/loader:1028:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:142:12)
at node:internal/main/run_main_module:28:49

Node.js v21.6.2
PS C:\Users\clou1\OneDrive\Desktop\atom bot>
deployCommandsF()
^

TypeError: deployCommandsF is not a function
at Object.<anonymous> (C:\Users\clou1\OneDrive\Desktop\atom bot\index.js:8:1)
at Module._compile (node:internal/modules/cjs/loader:1378:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1437:10)
at Module.load (node:internal/modules/cjs/loader:1212:32)
at Module._load (node:internal/modules/cjs/loader:1028:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:142:12)
at node:internal/main/run_main_module:28:49

Node.js v21.6.2
PS C:\Users\clou1\OneDrive\Desktop\atom bot> node .
C:\Users\clou1\OneDrive\Desktop\atom bot\index.js:8
deployCommandsF()
^

TypeError: deployCommandsF is not a function
at Object.<anonymous> (C:\Users\clou1\OneDrive\Desktop\atom bot\index.js:8:1)
at Module._compile (node:internal/modules/cjs/loader:1378:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1437:10)
at Module.load (node:internal/modules/cjs/loader:1212:32)
at Module._load (node:internal/modules/cjs/loader:1028:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:142:12)
at node:internal/main/run_main_module:28:49

Node.js v21.6.2
PS C:\Users\clou1\OneDrive\Desktop\atom bot>
39 Replies
d.js toolkit
d.js toolkitβ€’8mo 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! - βœ… Marked as resolved by OP
π’»π“‡π‘’π’Άπ“€π“Ž
const { REST, Routes } = require('discord.js');
const fs = require('node:fs');
const path = require('node:path');

function deployCommandsF() {
const commands = [];
// Grab all the command folders 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, folder);
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(),
{ 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);
}
})();
}

module.exports = deployCommandsF
const { REST, Routes } = require('discord.js');
const fs = require('node:fs');
const path = require('node:path');

function deployCommandsF() {
const commands = [];
// Grab all the command folders 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, folder);
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(),
{ 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);
}
})();
}

module.exports = deployCommandsF
const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, GatewayIntentBits } = require('discord.js');
const deployCommandsF = require('./deploy-commands')

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

deployCommandsF()

client.commands = new Collection();
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);

for (const folder of commandFolders) {
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}


client.login(token);
const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, GatewayIntentBits } = require('discord.js');
const deployCommandsF = require('./deploy-commands')

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

deployCommandsF()

client.commands = new Collection();
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);

for (const folder of commandFolders) {
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}


client.login(token);
Unknown User
Unknown Userβ€’8mo ago
Message Not Public
Sign In & Join Server To View
π’»π“‡π‘’π’Άπ“€π“Ž
Hi i dont understand this was a template from github
d.js docs
d.js docsβ€’8mo ago
:guide: Creating Your Bot: Registering slash commands read more :guide: Creating Your Bot: Command handling read more :guide: Creating Your Bot: Event handling read more
π’»π“‡π‘’π’Άπ“€π“Ž
@JΓ΄ πŸŒˆπŸ¦„ Ok i understand now so how do i make it work for all servers
d.js docs
d.js docsβ€’8mo ago
:guide: Creating Your Bot: Registering slash commands - Command registration > Global commands read more
π’»π“‡π‘’π’Άπ“€π“Ž
@JΓ΄ πŸŒˆπŸ¦„ Node.js v21.6.2 PS C:\Users\clou1\OneDrive\Desktop\atom bot> node . C:\Users\clou1\OneDrive\Desktop\atom bot\index.js:9 const foldersPath = path.join(__dirname, 'commands'); ^^^^^ SyntaxError: Unexpected token 'const' at internalCompileFunction (node:internal/vm:77:18) at wrapSafe (node:internal/modules/cjs/loader:1290:20) at Module._compile (node:internal/modules/cjs/loader:1342:27) at Module._extensions..js (node:internal/modules/cjs/loader:1437:10) at Module.load (node:internal/modules/cjs/loader:1212:32) at Module._load (node:internal/modules/cjs/loader:1028:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:142:12) at node:internal/main/run_main_module:28:49 Node.js v21.6.2 PS C:\Users\clou1\OneDrive\Desktop\atom bot> node . node:internal/modules/cjs/loader:1458 throw err; ^ SyntaxError: C:\Users\clou1\OneDrive\Desktop\atom bot\config.json: Unexpected token 'm', "module.exp"... is not valid JSON at parse (<anonymous>) at Module._extensions..json (node:internal/modules/cjs/loader:1455:39) at Module.load (node:internal/modules/cjs/loader:1212:32) at Module._load (node:internal/modules/cjs/loader:1028:12) at Module.require (node:internal/modules/cjs/loader:1237:19) at require (node:internal/modules/helpers:176:18) at Object.<anonymous> (C:\Users\clou1\OneDrive\Desktop\atom bot\index.js:2:38) at Module._compile (node:internal/modules/cjs/loader:1378:14) at Module._extensions..js (node:internal/modules/cjs/loader:1437:10) at Module.load (node:internal/modules/cjs/loader:1212:32) Node.js v21.6.2 PS C:\Users\clou1\OneDrive\Desktop\atom bot>
Unknown User
Unknown Userβ€’8mo ago
Message Not Public
Sign In & Join Server To View
π’»π“‡π‘’π’Άπ“€π“Ž
ok
const { REST, Routes } = require('discord.js');
const { clientId, guildId, token } = require('./config.json');
const fs = require('node:fs');
const path = require('node:path');

const commands = [];
// Grab all the command folders 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, folder);
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 commands = [];
// Grab all the command folders 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, folder);
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);
}
})();
Unknown User
Unknown Userβ€’8mo ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown Userβ€’8mo ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown Userβ€’8mo ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown Userβ€’8mo ago
Message Not Public
Sign In & Join Server To View
π’»π“‡π‘’π’Άπ“€π“Ž
i did yntaxError: C:\Users\clou1\OneDrive\Desktop\atom bot\config.json: Unexpected token 'm', "module.exp"... is not valid JSON at parse (<anonymous>) at Module._extensions..json (node:internal/modules/cjs/loader:1455:39) at Module.load (node:internal/modules/cjs/loader:1212:32) at Module._load (node:internal/modules/cjs/loader:1028:12) at Module.require (node:internal/modules/cjs/loader:1237:19) at require (node:internal/modules/helpers:176:18) at Object.<anonymous> (C:\Users\clou1\OneDrive\Desktop\atom bot\deploy-commands.js:2:38) at Module._compile (node:internal/modules/cjs/loader:1378:14) at Module._extensions..js (node:internal/modules/cjs/loader:1437:10) at Module.load (node:internal/modules/cjs/loader:1212:32)
{
"token": "AtRhNBQSgJFiJz2IMAYOmGA49FxtBcQbk",
"clientId": "12",
"guildId": "your-server-id-goes-here"
}
{
"token": "AtRhNBQSgJFiJz2IMAYOmGA49FxtBcQbk",
"clientId": "12",
"guildId": "your-server-id-goes-here"
}
Unknown User
Unknown Userβ€’8mo ago
Message Not Public
Sign In & Join Server To View
π’»π“‡π‘’π’Άπ“€π“Ž
i delete half of the token
Unknown User
Unknown Userβ€’8mo ago
Message Not Public
Sign In & Join Server To View
π’»π“‡π‘’π’Άπ“€π“Ž
i dont understand
Unknown User
Unknown Userβ€’8mo ago
Message Not Public
Sign In & Join Server To View
π’»π“‡π‘’π’Άπ“€π“Ž
how i got that error
Unknown User
Unknown Userβ€’8mo ago
Message Not Public
Sign In & Join Server To View
π’»π“‡π‘’π’Άπ“€π“Ž
im not how am i doing that
Unknown User
Unknown Userβ€’8mo ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docsβ€’8mo ago
:guide: Home: Introduction - Before you begin... read more
Unknown User
Unknown Userβ€’8mo ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown Userβ€’8mo ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown Userβ€’8mo ago
Message Not Public
Sign In & Join Server To View
π’»π“‡π‘’π’Άπ“€π“Ž
fixed it now im getting this WARNING] The command at C:\Users\clou1\OneDrive\Desktop\atom bot\commands\utility\steal-emoji.js is missing a required "data" or "execute" property. [WARNING] The command at C:\Users\clou1\OneDrive\Desktop\atom bot\commands\utility\whois.js is missing a required "data" or "execute" property. Started refreshing 0 application (/) commands. C:\Users\clou1\OneDrive\Desktop\atom bot\index.js:8 deployCommandsF() ^ TypeError: deployCommandsF is not a function at Object.<anonymous> (C:\Users\clou1\OneDrive\Desktop\atom bot\index.js:8:1) at Module._compile (node:internal/modules/cjs/loader:1378:14) at Module._extensions..js (node:internal/modules/cjs/loader:1437:10) at Module.load (node:internal/modules/cjs/loader:1212:32) at Module._load (node:internal/modules/cjs/loader:1028:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:142:12) at node:internal/main/run_main_module:28:49 Node.js v21.6.2 PS C:\Users\clou1\OneDrive\Desktop\atom bot>
Unknown User
Unknown Userβ€’8mo ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown Userβ€’8mo ago
Message Not Public
Sign In & Join Server To View
π’»π“‡π‘’π’Άπ“€π“Ž
ok /sloved ?sloved !sloved /sloved ?
Unknown User
Unknown Userβ€’8mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server