How can i use global slash command in discord.js v13?


I’ve created a simple slash command. It works on the only guild. before that, I was using v12. Now I wanna switch to v13.
Now how can I make these global slash commands?

Code

client.on ("ready", () => {
 
    console.log(`${client.user.tag} Has logged in`)
  client.user.setActivity(`/help | ${client.user.username}`, { type: "PLAYING" })

    const guildId = "914573324485541928"
    const guild = client.guilds.cache.get(guildId)
    let commands

    if (guild) {
      commands = guild.commands
    } else {
      commands = client.application.commands
    }

    commands.create({
      name: 'ping',
      description: 'Replies with pong'
    })
    commands.create({
      name: 'truth',
      description: 'Replies with truth'
    })

  }); 
  client.on('interactionCreate', async (interaction) => {
    if(!interaction.isCommand()){
      return
    }

    const { commandName, options } = interaction 

    if (commandName === 'ping'){
      interaction.reply({
        content: 'pong'
      })
    }
    ```

I'm new in v13 so please explain it simply :|  

Source: JavaSript – Stack Overflow

November 29, 2021
Category : News
Tags: discord | discord.js | javascript

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.