#Issue with ClientApplication always being null

6 messages · Page 1 of 1 (latest)

fading niche
#

Hello, I'm trying to register application commands by doing client.application?.commands.create(). The problem is that my client.application is always null and nothing happens when I attempt to create commands this way.

const initializeCommands = async (): Promise<void> => {
  for(const folder of commandFolders) {
    const commandFolder: string[] = fs.readdirSync(commandsPath + `/${folder}`)
    const commandFiles: string[] = commandFolder.filter(file => file.endsWith('.ts'))

    for(const file of commandFiles) {
      const filePath: string = path.join(commandsPath, `/${folder}/${file}`)
      const command: Command = (await import(filePath)).command
  
      if(!command) return log.warn(`Invaild command at: ${filePath}`, WarnLevel.Medium)
  
      if(globalPush) await client.application?.commands.create(command.data)
      else await client.application?.commands.create(command.data, process.env.DEV_GUILD as string)
      
      log.command(command)
    }
  }
}
#

• 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.

#

discordjs ver: ^14.7.1
node ver: 18.12.1

dense lotus
#

If you don't want it to be null, you should call your function when your client is connected to the gateway, or use REST

fading niche
dense lotus
#

Yes