Ping command help - Beginner

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
22 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
NanotechPikachu
NanotechPikachuOP2y ago
As i said earlier, I am beginner
Danial
Danial2y ago
You should try the code in the guide, and if you have any errors, send them here so we can help you solve them
d.js docs
d.js docs2y ago
property Client#ws The WebSocket manager of the client
NanotechPikachu
NanotechPikachuOP2y ago
I can't understand a single thing in that
Danial
Danial2y ago
Do you know JavaScript?
NanotechPikachu
NanotechPikachuOP2y ago
Well, truthfully no. I was just trying.
Danial
Danial2y ago
Then you'd wanna start by learning JavaScript first, check out #resources and #useful-servers, you can't really do much and won't understand anything without learning it
NanotechPikachu
NanotechPikachuOP2y ago
I know that i need to know js. The problem isnt that. The code in guide must work na? I copied it and still it didn't work. Well, am i missing anything?
Danial
Danial2y ago
It does work, "didn't work" doesn't really help us help you solve the issue you're having, any errors?
NanotechPikachu
NanotechPikachuOP2y ago
The guide tells me to create a folder and store the slash cmd there. I stored it and when i search for the slash cmd, there is none I will try again then
Danial
Danial2y ago
Alright
NanotechPikachu
NanotechPikachuOP2y ago
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);
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
NanotechPikachu
NanotechPikachuOP2y ago
The error
Danial
Danial2y ago
A great example of why you need to learn JavaScript before you continue, you're importing Client twice
NanotechPikachu
NanotechPikachuOP2y ago
Hmmm so, do i have to remove the first
const { Client....}
const { Client....}
? The heck. Now i see it, i have made the same code twice Bruh. Another error came Lemme try to find In the code, it says collection isn't defined
Danial
Danial2y ago
#rules 2 and 5
NanotechPikachu
NanotechPikachuOP2y ago
I understand that i come from rule 2 but, not 5
Danial
Danial2y ago
You don't know JavaScript so anyone who'd wanna help would need to hold your hand entirely and explain even basic things
NanotechPikachu
NanotechPikachuOP2y ago
Well, I can't deny it as it's partially true. Hmmmm.... I think py is best suited for me despite just knowing some looping i created codes..... Hmmmm Anyway, thnx for ur time Well, any idea to close this?
Danial
Danial2y ago
Of course, and don't think you need to, it'll close automatically after inactivity
NanotechPikachu
NanotechPikachuOP2y ago
Hmmm ok
Want results from more Discord servers?
Add your server