Xenon
Xenon
DIAdiscord.js - Imagine an app
Created by Xenon on 10/1/2024 in #djs-questions
help meeded
code-
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),
async execute(interaction) {
try {
// Defer the reply immediately to prevent timeout and ensure you can reply later
await interaction.deferReply({ ephemeral: false });

// Calculate the latencies
const botLatency = Date.now() - interaction.createdTimestamp;
const discordLatency = Math.round(interaction.client.ws.ping);

// Create the embed with the latency details
const embed = new EmbedBuilder()
.setColor('#00ffff')
.setTitle('Pong!')
.setDescription(`**Bot Latency:** \`${botLatency}ms\`\n**Discord Latency:** \`${discordLatency >= 0 ? discordLatency : 0}ms\``);

// Edit the reply with the embed content
await interaction.editReply({ embeds: [embed] });
} catch (error) {
console.error('Error executing ping command:', error);

// Send an error message only if the interaction has not been replied to or deferred
if (!interaction.deferred && !interaction.replied) {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
},
};
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),
async execute(interaction) {
try {
// Defer the reply immediately to prevent timeout and ensure you can reply later
await interaction.deferReply({ ephemeral: false });

// Calculate the latencies
const botLatency = Date.now() - interaction.createdTimestamp;
const discordLatency = Math.round(interaction.client.ws.ping);

// Create the embed with the latency details
const embed = new EmbedBuilder()
.setColor('#00ffff')
.setTitle('Pong!')
.setDescription(`**Bot Latency:** \`${botLatency}ms\`\n**Discord Latency:** \`${discordLatency >= 0 ? discordLatency : 0}ms\``);

// Edit the reply with the embed content
await interaction.editReply({ embeds: [embed] });
} catch (error) {
console.error('Error executing ping command:', error);

// Send an error message only if the interaction has not been replied to or deferred
if (!interaction.deferred && !interaction.replied) {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
},
};
5 replies
DIAdiscord.js - Imagine an app
Created by Xenon on 8/14/2024 in #djs-questions
Error on ticketing bot
8 replies
DIAdiscord.js - Imagine an app
Created by Xenon on 8/14/2024 in #djs-questions
Error on ticketing bot
8 replies
DIAdiscord.js - Imagine an app
Created by Xenon on 8/14/2024 in #djs-questions
Error on ticketing bot
8 replies
DIAdiscord.js - Imagine an app
Created by Xenon on 8/14/2024 in #djs-questions
error in sharding
ok
12 replies
DIAdiscord.js - Imagine an app
Created by Xenon on 8/14/2024 in #djs-questions
error in sharding
then how to resolve this?
12 replies
DIAdiscord.js - Imagine an app
Created by Xenon on 8/14/2024 in #djs-questions
error in sharding
this error is faced by me
12 replies
DIAdiscord.js - Imagine an app
Created by Xenon on 8/14/2024 in #djs-questions
error in sharding
No description
12 replies
DIAdiscord.js - Imagine an app
Created by Xenon on 8/14/2024 in #djs-questions
error in sharding
please help me
12 replies
DIAdiscord.js - Imagine an app
Created by Xenon on 8/14/2024 in #djs-questions
error in sharding
ok
12 replies
DIAdiscord.js - Imagine an app
Created by Xenon on 8/14/2024 in #djs-questions
error in sharding
12 replies
DIAdiscord.js - Imagine an app
Created by Xenon on 8/14/2024 in #djs-questions
error in sharding
bot.js
12 replies
DIAdiscord.js - Imagine an app
Created by Xenon on 8/14/2024 in #djs-questions
error in sharding
index.js const { ShardingManager } = require('discord.js'); const dotenv = require('dotenv'); dotenv.config(); const totalClusters = 2; const totalShards = 10; // Initialize the ShardingManager const manager = new ShardingManager('./bot.js', { token: process.env.TOKEN, totalShards: totalShards, }); // Event listeners for shard lifecycle events manager.on('shardCreate', shard => { const clusterID = Math.floor(shard.id / Math.ceil(totalShards / totalClusters)); console.log([ SHARD ] Shard ${shard.id} in cluster ${clusterID} is deployed); shard.on('ready', () => { console.log([ SHARD ] Shard ${shard.id} is ready); }); shard.on('error', error => { console.error([ SHARD ERROR ] Shard ${shard.id} encountered an error:, error); }); shard.on('disconnect', () => { console.log([ SHARD ] Shard ${shard.id} disconnected); }); shard.on('reconnecting', () => { console.log([ SHARD ] Shard ${shard.id} is reconnecting); }); shard.on('death', process => { console.log([ SHARD ] Shard ${shard.id} process exited with code ${process.exitCode}); }); }); // Spawn the shards with a delay of 5 seconds between each spawn manager.spawn({ amount: totalShards, delay: 5000 }).catch(error => { console.error('Error spawning shards:', error); });
12 replies