Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

749
Vistas
Discord only recognizing "ping" command in discord.js

In my Discord.JS bot, I have multiple commands setup (ping, beep, etc.) but Discord only recognizes "ping". I have tried multiple setups, and all are the same.

Here is my code:

const { Client, Intents } = require('discord.js');
const { token } = require('./config.json');

const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });

client.once('ready', () => {
    console.log('Ready!');
});

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

    const { commandName: command } = interaction;

    if (command === 'ping') {
        await interaction.reply('Pong!');
    } else if (command === 'beep') {
        await interaction.reply('Boop!');
    } else if (command === 'server') {
        await interaction.reply(`Server name: ${interaction.guild.name}\nTotal members: ${interaction.guild.memberCount}`);
    } else if (command === 'user-info') {
        await interaction.reply(`Your username: ${interaction.user.username}\nYour ID: ${interaction.user.id}`);
    }
});

client.login(token);

And here is Discords command view when "/" is enter

Discords command view

As you can see, ping is the only thing being recognized by discord.

It is also worth noting the ‘ping’ command has a description which the original description I setup, so it seems like issue is that Discord is not updating the commands each time the script changes. But, I don’t know how to resolve that issue.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

It seems like you only registered the ping command. You have to register each slash command individually.

I guess you registered the slashcommand some tile earlier, and have not removed it since. You are only responding in your code example to slashcommands, but you have to create them in the first hand. Check here on how to do that.

it may take up to one hour to register a global command tho, so be patient. If you are fine, with slashcommands for one guild only, you can also only create guildCommands. These are up and running within a view minutes (under 10minutes max)


Here is a simple command, with which you can update the slashcommands (this is staright from the docs)

client.on('messageCreate', async message => {
    if (!client.application?.owner) await client.application?.fetch();

    if (message.content.toLowerCase() === '!deploy' && message.author.id === client.application?.owner.id) {
        const data = [
            {
                name: 'ping',
                description: 'Replies with Pong!',
            },
            {
                name: 'pong',
                description: 'Replies with Ping!',
            },
        ];

        const commands = await client.application?.commands.set(data);
        console.log(commands);
    }
});

NOTE: you have to be running the master branch of discord.js (aka Discord.js V13). If you have not installed it yet, you can install it by running: npm install discord.js@latest. Make sure, you have uninstalled the "normal" discord.js dependency beforehand, by running npm uninstall discord.js.

If you are not sure what version you currently have installed, simply run npm list

over 4 years ago · Santiago Trujillo Denunciar

0

This worked for me, the idea is to render each command separately.

I also went for some hardcoded configs: guild_id & client_id (to win some time in dev mode)

const { Client, Collection, Intents } = require('discord.js');
const { token, client_id, guild_id } = require('./config.json');

const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });

client.once('ready', () => {
    console.log('Ready!');
});


client.on('messageCreate', async message => {
    if (!client.application?.owner) await client.application?.fetch();

    // => client_id was just a quick fix, the correct value should be the id of the guild owner(s)
    if (message.content.toLowerCase() === '!deploy' && message.author.id === client_id) {
        const data = [
            {
                name: 'ping',
                description: 'Replies with Pong!',
            },
            {
                name: 'foo',
                description: 'Replies with bar!',
            },
            {
                name: 'chicken',
                description: 'Replies with sticks!',
            },
        ];

        // same here, guild_id should also be replaced by the correct call to the idea number, just as client_id in this code!
        for (let i = 0; data.length > i; i++) {
            await client.guilds.cache.get(guild_id)?.commands.create(data[i]);

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

    const command = interaction.commandName;

    if (command === 'ping') {
        await interaction.reply('pong')
    } else if (command === 'foo') {
        await interaction.reply('bar')
    } else if (command === 'chicken') {
        await interaction.reply('nuggets')
    }
});

client.login(token);
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda