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 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!
treble/luna
treble/luna16mo ago
did you deploy your commands
racinggecko
racinggeckoOP16mo ago
no, how do I do so? sorry, I'm new to discord.js
d.js docs
d.js docs16mo ago
guide Creating Your Bot: Registering slash commands read more
treble/luna
treble/luna16mo ago
no worries, we all have to start somewhere
racinggecko
racinggeckoOP16mo 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/luna16mo ago
did you run your deploy script
racinggecko
racinggeckoOP16mo ago
yes
treble/luna
treble/luna16mo ago
can you show that script and any output you got
racinggecko
racinggeckoOP16mo 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/luna16mo ago
those errors are unrelated are you actually running your deploy file? running your index file does not run your deploy file
racinggecko
racinggeckoOP16mo ago
I used node deploy-commands.js
treble/luna
treble/luna16mo ago
and do you get any output from that
racinggecko
racinggeckoOP16mo 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/luna16mo ago
whats your node version iirc you can just use require('fs')
racinggecko
racinggeckoOP16mo ago
in the code or console command?
treble/luna
treble/luna16mo ago
in your code
racinggecko
racinggeckoOP16mo ago
ok
treble/luna
treble/luna16mo ago
also, whats your node version node -v
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
treble/luna
treble/luna16mo ago
yeah i cant remember whether it was, i use it all the time but i dont remember having to install it
racinggecko
racinggeckoOP16mo ago
version is 17.9.0 it updated to 20.5.0 when I tried to run deploy-commands.js now but now my bot code doesn't work with latest version
treble/luna
treble/luna16mo ago
define doesn't work
racinggecko
racinggeckoOP16mo ago
other packages I used in the bot were compiled with node module version 72 and when it updated it now requires version 115
treble/luna
treble/luna16mo ago
do you need those packages?
racinggecko
racinggeckoOP16mo ago
yes
treble/luna
treble/luna16mo ago
also, i checked, fs comes with node you can try switching back then and usign what i said, that should work
racinggecko
racinggeckoOP16mo ago
can't revert to old node version
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
treble/luna
treble/luna16mo ago
i just installed node and it came with it
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
racinggecko
racinggeckoOP16mo ago
fixed node error, trying what you did
Want results from more Discord servers?
Add your server