Enabling / commands

Hi, I'm trying to enable slash commands on my bot. I set a prefix variable in index.js and the value is "/". However, after 48 hours of having the bot in my server, the bot commands don't show when typing /. Is there a different way of coding this that could help?
33 Replies
d.js toolkit
d.js toolkit13mo 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!
treble/luna
treble/luna13mo ago
did you deploy your commands
racinggecko
racinggecko13mo ago
no, how do I do so? sorry, I'm new to discord.js
d.js docs
d.js docs13mo ago
guide Creating Your Bot: Registering slash commands read more
treble/luna
treble/luna13mo ago
no worries, we all have to start somewhere
racinggecko
racinggecko13mo ago
ok, I've finished writing the code for deploying it says I should be able to type / and see my bot but I still can't do so, even though the code has no errors
treble/luna
treble/luna13mo ago
did you run your deploy script
racinggecko
racinggecko13mo ago
yes
treble/luna
treble/luna13mo ago
can you show that script and any output you got
racinggecko
racinggecko13mo ago
const { REST, Routes } = require('discord.js');
const { CLIENT_ID, SERVER_ID, TOKEN } = require('./config.js');
const fs = require('node:fs');
const path = require('node:path');

const commands = [mod, utility];
// Grab all the command files from the commands directory you created earlier
const foldersPath = path.join(__dirname, 'commands');
const commandsPath = fs.readdirSync(commands);
n
for (const folder of command) {
// 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(CLIENT_ID, SERVER_ID),
{ 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 { CLIENT_ID, SERVER_ID, TOKEN } = require('./config.js');
const fs = require('node:fs');
const path = require('node:path');

const commands = [mod, utility];
// Grab all the command files from the commands directory you created earlier
const foldersPath = path.join(__dirname, 'commands');
const commandsPath = fs.readdirSync(commands);
n
for (const folder of command) {
// 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(CLIENT_ID, SERVER_ID),
{ 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);
}
})();
and here's the error /home/runner/bot-1/handler/console.js:5 bot.channels.cache.get(message.channel.id).send(x.join(" ")); ^ TypeError: Cannot read property 'channel' of undefined at ReadStream.<anonymous> (/home/runner/Lizard-1/handler/console.js:5:44) at ReadStream.emit (events.js:314:20) at addChunk (_stream_readable.js:297:12) at readableAddChunk (_stream_readable.js:272:9) at ReadStream.Readable.push (_stream_readable.js:213:10) at TTY.onStreamRead (internal/stream_base_commons.js:188:23) exit status 1
treble/luna
treble/luna13mo ago
those errors are unrelated are you actually running your deploy file? running your index file does not run your deploy file
racinggecko
racinggecko13mo ago
I used node deploy-commands.js
treble/luna
treble/luna13mo ago
and do you get any output from that
racinggecko
racinggecko13mo ago
Error: Cannot find module 'node:fs' Require stack: - /home/runner/bot-1/deploy-commands.js at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15) at Function.Module._load (internal/modules/cjs/loader.js:667:27) at Module.require (internal/modules/cjs/loader.js:887:19) at require (internal/modules/cjs/helpers.js:74:18) at Object.<anonymous> (/home/runner/bot-1/deploy-commands.js:3:12) at Module._compile (internal/modules/cjs/loader.js:999:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10) at Module.load (internal/modules/cjs/loader.js:863:32) at Function.Module._load (internal/modules/cjs/loader.js:708:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12) { code: 'MODULE_NOT_FOUND', requireStack: [ '/home/runner/bot-1/deploy-commands.js' ]
treble/luna
treble/luna13mo ago
whats your node version iirc you can just use require('fs')
Want results from more Discord servers?
Add your server