Slash Commands Not Loading

So my bot is working perfectly but when I add it into a new server slash commands don't load like at all. No errors, it has administrator along with application.commands auth.
67 Replies
d.js toolkit
d.js toolkit6mo 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
Evelynn
EvelynnOP6mo ago
its maybe supposed to load after some time??
Evelynn
EvelynnOP6mo ago
No description
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
I do not pose any specific code that targets guild id's, though, I have a a specific channel only command in which it still doesn't work, I tried updating the channel id to a channel from the server I tried adding it to. Providing the register code in a sec
// Slash
client.slashcommands = new Discord.Collection()
let commands = []
const slashFiles = fs
.readdirSync("./slash")
.filter((file) => file.endsWith(".js"))
for (const file of slashFiles) {
const slashcmd = require(`./slash/${file}`)
client.slashcommands.set(slashcmd.data.name, slashcmd)
commands.push(slashcmd.data.toJSON())
}

(async () => {
const rest = new REST({ version: "10" }).setToken(TOKEN)
console.log("(/) commands are refreshed.")
await rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), {
body: commands,
})
.then(() => {
console.log("↳ (/) commands are loaded.")
console.log(date.toUTCString())
})
.catch((err) => {
if (err) {
console.log(err)
process.exit(1)
}
})

await client.login(TOKEN).then(() => {
console.log("Bot is started.")
})
})()
// Slash
client.slashcommands = new Discord.Collection()
let commands = []
const slashFiles = fs
.readdirSync("./slash")
.filter((file) => file.endsWith(".js"))
for (const file of slashFiles) {
const slashcmd = require(`./slash/${file}`)
client.slashcommands.set(slashcmd.data.name, slashcmd)
commands.push(slashcmd.data.toJSON())
}

(async () => {
const rest = new REST({ version: "10" }).setToken(TOKEN)
console.log("(/) commands are refreshed.")
await rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), {
body: commands,
})
.then(() => {
console.log("↳ (/) commands are loaded.")
console.log(date.toUTCString())
})
.catch((err) => {
if (err) {
console.log(err)
process.exit(1)
}
})

await client.login(TOKEN).then(() => {
console.log("Bot is started.")
})
})()
im a beginner so there might be a mistake
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
my apologies I thought you asked for guild-id specific code
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
how do you suggest I change it
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
also does this basically mean commands are loaded for servers that are existant while bot is being started? (registering per guild)
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
so I make body [], start the bot then change the line you wanted and restart?
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
bot only has a single command made for a specific purpose
d.js docs
d.js docs6mo ago
:guide: Creating Your Bot: Registering slash commands read more
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
oh you mean like that ohh they save?
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
I thought they had to be registered every time bot starts
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
but whenever I edit a command code I gotta register right for the edit to take effect
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
aight the reset of the body is in effect ill revert the body and change the code
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
I reset the body, publish, revert the body, change the code you asked me to but the new server still doesn't have the commands should I like wait for some time or no errors
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
of course
client.slashcommands = new Discord.Collection()
let commands = []
const slashFiles = fs
.readdirSync("./slash")
.filter((file) => file.endsWith(".js"))
for (const file of slashFiles) {
const slashcmd = require(`./slash/${file}`)
client.slashcommands.set(slashcmd.data.name, slashcmd)
commands.push(slashcmd.data.toJSON())
}

(async () => {
const rest = new REST({ version: "10" }).setToken(TOKEN)
console.log("(/) commands are being refreshed.")
await rest.put(Routes.applicationCommands(CLIENT_ID), {
body: commands,
})
.then(() => {
console.log("↳ (/) commands are loaded.")
console.log(date.toUTCString())
})
.catch((err) => {
if (err) {
console.log(err)
process.exit(1)
}
})

await client.login(TOKEN).then(() => {
console.log("Bot started.")
})
})()
client.slashcommands = new Discord.Collection()
let commands = []
const slashFiles = fs
.readdirSync("./slash")
.filter((file) => file.endsWith(".js"))
for (const file of slashFiles) {
const slashcmd = require(`./slash/${file}`)
client.slashcommands.set(slashcmd.data.name, slashcmd)
commands.push(slashcmd.data.toJSON())
}

(async () => {
const rest = new REST({ version: "10" }).setToken(TOKEN)
console.log("(/) commands are being refreshed.")
await rest.put(Routes.applicationCommands(CLIENT_ID), {
body: commands,
})
.then(() => {
console.log("↳ (/) commands are loaded.")
console.log(date.toUTCString())
})
.catch((err) => {
if (err) {
console.log(err)
process.exit(1)
}
})

await client.login(TOKEN).then(() => {
console.log("Bot started.")
})
})()
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
I appreciate the help, im the one getting helped here
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
aight
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
all good
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
I did I made sure it got published
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
waited till it was all deployed and then reverted the body and changed it to non-guilfd no the commands weren't loaded when the body was [] but I can retry if you'd like
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
nothing, no errors, no commands same as before
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
only error I got
No description
Evelynn
EvelynnOP6mo ago
bot started etc also a "commands refreshed" & "commands loaded" print absolutely no other prints if its supposed to fix this I can maybe transfer it to another application???
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
require("dotenv").config()
const Discord = require("discord.js")
const { REST } = require("@discordjs/rest")
const { Routes } = require("discord-api-types/v10")
const fs = require("fs")
const date = new Date()
const TOKEN = process.env.TOKEN
const CLIENT_ID = process.env.CLIENT_ID
const GUILD_ID = process.env.GUILD_ID
const { GatewayIntentBits, Partials } = require("discord.js")

const client = new Discord.Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent,
],
partials: [Partials.GuildMember],
})

// Button
client.buttons = new Discord.Collection()
const buttonFiles = fs
.readdirSync("./button")
.filter((file) => file.endsWith(".js"))
for (const file of buttonFiles) {
const button = require(`./button/${file}`)
client.buttons.set(button.name, button)
}
// Event
const eventFiles = fs
.readdirSync("./events")
.filter((file) => file.endsWith(".js"))
for (const file of eventFiles) {
const event = require(`./events/${file}`)

if (event.once) {
client.once(event.name, (...args) =>
event.execute(...args, client)
)
} else {
client.on(event.name, (...args) =>
event.execute(...args, client)
)
}
}
// Slash Commands
client.slashcommands = new Discord.Collection()
let commands = []
const slashFiles = fs
.readdirSync("./slash")
.filter((file) => file.endsWith(".js"))
for (const file of slashFiles) {
const slashcmd = require(`./slash/${file}`)
client.slashcommands.set(slashcmd.data.name, slashcmd)
commands.push(slashcmd.data.toJSON())
}

(async () => {
const rest = new REST({ version: "10" }).setToken(TOKEN)
console.log("(/) commands are being refreshed.")
await rest.put(Routes.applicationCommands(CLIENT_ID), {
body: commands,
})
.then(() => {
console.log("↳ (/) commands are loaded.")
console.log(date.toUTCString())
})
.catch((err) => {
if (err) {
console.log(err)
process.exit(1)
}
})

await client.login(TOKEN).then(() => {
console.log("Bot started.")
})
})()
require("dotenv").config()
const Discord = require("discord.js")
const { REST } = require("@discordjs/rest")
const { Routes } = require("discord-api-types/v10")
const fs = require("fs")
const date = new Date()
const TOKEN = process.env.TOKEN
const CLIENT_ID = process.env.CLIENT_ID
const GUILD_ID = process.env.GUILD_ID
const { GatewayIntentBits, Partials } = require("discord.js")

const client = new Discord.Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent,
],
partials: [Partials.GuildMember],
})

// Button
client.buttons = new Discord.Collection()
const buttonFiles = fs
.readdirSync("./button")
.filter((file) => file.endsWith(".js"))
for (const file of buttonFiles) {
const button = require(`./button/${file}`)
client.buttons.set(button.name, button)
}
// Event
const eventFiles = fs
.readdirSync("./events")
.filter((file) => file.endsWith(".js"))
for (const file of eventFiles) {
const event = require(`./events/${file}`)

if (event.once) {
client.once(event.name, (...args) =>
event.execute(...args, client)
)
} else {
client.on(event.name, (...args) =>
event.execute(...args, client)
)
}
}
// Slash Commands
client.slashcommands = new Discord.Collection()
let commands = []
const slashFiles = fs
.readdirSync("./slash")
.filter((file) => file.endsWith(".js"))
for (const file of slashFiles) {
const slashcmd = require(`./slash/${file}`)
client.slashcommands.set(slashcmd.data.name, slashcmd)
commands.push(slashcmd.data.toJSON())
}

(async () => {
const rest = new REST({ version: "10" }).setToken(TOKEN)
console.log("(/) commands are being refreshed.")
await rest.put(Routes.applicationCommands(CLIENT_ID), {
body: commands,
})
.then(() => {
console.log("↳ (/) commands are loaded.")
console.log(date.toUTCString())
})
.catch((err) => {
if (err) {
console.log(err)
process.exit(1)
}
})

await client.login(TOKEN).then(() => {
console.log("Bot started.")
})
})()
whole script
d.js docs
d.js docs6mo ago
:guide: Creating Your Bot: Registering slash commands read more
Evelynn
EvelynnOP6mo ago
aight ill do that praying that I won't break the bot
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
hope so also in guide it reads
node deploy-commands.js
node deploy-commands.js
, should I run this in VSC terminal? Hosting website I use doesn't pose a terminal I think
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
should I also put button/event registers to the new register script? or only commands
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
aight one question, since im keeping buttons/events at the main script, how should I pass the client? it creates the client object via Discord.js package at the main script
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
but the register script requires it too I don't?
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
basically while I was making this bot I wasn't aware of any of this so I made it like
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
interaction handler was working this way
client.slashcommands.get(interaction.commandName)
client.slashcommands.get(interaction.commandName)
client.slashcommands = new Discord.Collection()
client.slashcommands.set(slashcmd.data.name, slashcmd)
client.slashcommands = new Discord.Collection()
client.slashcommands.set(slashcmd.data.name, slashcmd)
and the register like this ik its stupid but this was the only way as I knew of whats the alternative so I can get rid of this
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
right yeah
d.js docs
d.js docs6mo ago
:guide: Creating Your Bot: Command handling read more
Evelynn
EvelynnOP6mo ago
this seemed smart at first but now ik how bad it is
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
also in the guide you sent it registers the commands with
applicationGuildCommands
applicationGuildCommands
should I change it
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Evelynn
EvelynnOP6mo ago
aight added the register file, trying aight so I added the register file ran the code bot is online with no errors but the hosting service I use (Railway) only allows terminal commands from desktop CLI, I downloaded n all but having some trouble with running the register code is there any alternative like a one time thing for this
TypeError: (intermediate value).setToken(...) is not a function
TypeError: (intermediate value).setToken(...) is not a function
const { REST, Routes } = require("discord.js")

const rest = new REST().setToken(TOKEN)
const { REST, Routes } = require("discord.js")

const rest = new REST().setToken(TOKEN)
these are direct references from discord js guide so idk how its erroring token is directly defined as a string yea if figured that out aigh yup it worked with a ; thank you
Want results from more Discord servers?
Add your server