#Ping command help - Beginner

29 messages · Page 1 of 1 (latest)

weary scaffold
#

Hi.
I am just a beginner in discord.js. I have done some projects in discord.py.

My problem is that, I cannot get heads or tails to make a Ping command in js. I tried the example in guide too as well as in stackoverflow but, couldn't get it

I know at least i should give an example, but, i cannot cuz no code is usable for me(as far as i saw).

I am thinking of a ping slash command. If u could help me with such a command that has an embed counting the latency and api. It would be helpful for me to understand better.

Also, I am using replit to code.

Sorry for this foolish question. I can't get any better way other than this

inner flame
#

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

weary scaffold
#

As i said earlier, I am beginner

plucky flower
half gateBOT
weary scaffold
plucky flower
weary scaffold
plucky flower
weary scaffold
plucky flower
weary scaffold
#

I will try again then

plucky flower
#

Alright

weary scaffold
#
const Discord = require('discord.js');

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

const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.once(Events.ClientReady, c => {
    console.log(`Ready! Logged in as ${c.user.tag}`);
});

const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');

client.commands = new Collection();
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
    const filePath = path.join(commandsPath, file);
    const command = require(filePath);

    if ('data' in command && 'execute' in command) {
        client.commands.set(command.data.name, command);
    } else {
        console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
    }
      }
client.on(Events.InteractionCreate, interaction => {
    if (!interaction.isChatInputCommand()) return;
    console.log(interaction);
});
client.on(Events.InteractionCreate, async interaction => {
    if (!interaction.isChatInputCommand()) return;

    const command = interaction.client.commands.get(interaction.commandName);

    if (!command) {
        console.error(`No command matching ${interaction.commandName} was found.`);
        return;
    }

    try {
        await command.execute(interaction);
    } catch (error) {
        console.error(error);
        if (interaction.replied || interaction.deferred) {
            await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
        } else {
            await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
        }
    }
});
client.login(token);
#

Well, this is my cmd in index.js

#

The error

plucky flower
weary scaffold
#

The heck. Now i see it, i have made the same code twice

weary scaffold
#

Bruh. Another error came

#

Lemme try to find

weary scaffold
plucky flower
weary scaffold
plucky flower
weary scaffold
#

Well, any idea to close this?

plucky flower
#

Of course, and don't think you need to, it'll close automatically after inactivity