Slash commands are not registered

I cleared commands with [], the commands cleared successfully. I re-register commands, commands that were previously registered appear, but my new file still does not want to register deploy-commands.js:
import { REST, Routes } from 'discord.js'
import * as commandModules from '../commands/index.js'
import { config } from '../config.js'

const commands = []

for (const module of Object.values(commandModules)) {
commands.push(module.data)
}

const rest = new REST({ version: '10' }).setToken(config.DISCORD_TOKEN)

rest
.put(Routes.applicationCommands(config.CLIENT_ID), { body: commands })
.then(() => {
console.log('Successfully registered application commands')
process.exit(0)
})
.catch(console.error)
import { REST, Routes } from 'discord.js'
import * as commandModules from '../commands/index.js'
import { config } from '../config.js'

const commands = []

for (const module of Object.values(commandModules)) {
commands.push(module.data)
}

const rest = new REST({ version: '10' }).setToken(config.DISCORD_TOKEN)

rest
.put(Routes.applicationCommands(config.CLIENT_ID), { body: commands })
.then(() => {
console.log('Successfully registered application commands')
process.exit(0)
})
.catch(console.error)
hello.js:
import {SlashCommandBuilder} from 'discord.js'

export const data = new SlashCommandBuilder()
.setName('hello')
.setDescription('hello.')

export async function execute(interaction, client) {
await interaction.reply(`This command was run by ${interaction.user.username}, who joined on ${interaction.member.joinedAt}.`)
}
import {SlashCommandBuilder} from 'discord.js'

export const data = new SlashCommandBuilder()
.setName('hello')
.setDescription('hello.')

export async function execute(interaction, client) {
await interaction.reply(`This command was run by ${interaction.user.username}, who joined on ${interaction.member.joinedAt}.`)
}
10 Replies
d.js toolkit
d.js toolkit3y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Rhae
Rhae3y ago
Log module in your for loop
vlad vollar
vlad vollarOP3y ago
?
Rhae
Rhae3y ago
? It means console log your module to make sure it's passing correctly what commands needs to be
vlad vollar
vlad vollarOP3y ago
The "hello" command is not displayed in the console, but all the rest commands are displayed without problems I can't figure out what's the problem
Rhae
Rhae3y ago
Can you show the log? So the rest of your commands get registered but this doesnt?
vlad vollar
vlad vollarOP3y ago
Yes, the rest of my* commands get registered but this doesn't Log: https://pastebin.com/fzcS7gX9
Pastebin
SlashCommandBuilder { options: [], name: 'afk', name_localizatio...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Rhae
Rhae3y ago
And you made sure to add to your export in commands/index.js?
vlad vollar
vlad vollarOP3y ago
I forgot... Sorry for my inattention, I haven't opened the code for several months and have already forgotten everything... Thank you!
Rhae
Rhae3y ago
No problem, I forget all the time so I know. 🙂

Did you find this page helpful?