the !shard command logs do not work in shard 1

.
6 Replies
d.js toolkit
d.js toolkit5mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
./u.7-z
./u.7-z5mo ago
hi
const { EmbedBuilder, ChannelType, ShardClientUtil } = require('discord.js');
const { shardIDMax } = require('../config.json');

module.exports = {
name: 'shard',
description: 'Obtiens l\'ID du Shard du serveur.',
execute(message) {
const client = message.client;
const currentShard = getGuildShardId(message.guild) + 1;
const totalUsers = client.users.cache.size;
const shardMax = shardIDMax;
const totalShardGuilds = Math.round(client.guilds.cache.size - 4);

function getGuildShardId(guild) {
return guild.shardId;
}

const defaultEmbed = new EmbedBuilder()
.setColor('#0099ff')
.setTitle(`Shard`)
.setDescription(`## Le serveur est dans la shard N°${currentShard}/${shardMax}\n Ce shard s'occupe de ${totalShardGuilds} serveurs et de ${totalUsers} utilisateurs`);

message.channel.send({ embeds: [defaultEmbed] })
.catch(error => console.error('Erreur lors de l\'envoi du message :', error));

const ping = Date.now() - message.createdTimestamp;
const memoryUsage = process.memoryUsage().heapUsed / 1024 / 1024;
const roundedMemory = Math.round(memoryUsage * 100) / 100;
const roundedping = Math.abs(ping);

const guildId = message.guild.id;
const guildname = message.guild.name;
const username = message.author.username;
const userid = message.author.id;
const shardId = getGuildShardId(message.guild) + 1;

const log = `Commande !shard exécutée en ${roundedping}ms dans (${guildId}) \`${guildname}\` par (${userid}) ${username} dans la shard ${shardId}`;
console.log(log);

const channelId = '1203418114402820146'; // Remplace par l'ID de ton canal
const channel = message.client.channels.cache.get(channelId);
if (channel) {
channel.send(log)
const { EmbedBuilder, ChannelType, ShardClientUtil } = require('discord.js');
const { shardIDMax } = require('../config.json');

module.exports = {
name: 'shard',
description: 'Obtiens l\'ID du Shard du serveur.',
execute(message) {
const client = message.client;
const currentShard = getGuildShardId(message.guild) + 1;
const totalUsers = client.users.cache.size;
const shardMax = shardIDMax;
const totalShardGuilds = Math.round(client.guilds.cache.size - 4);

function getGuildShardId(guild) {
return guild.shardId;
}

const defaultEmbed = new EmbedBuilder()
.setColor('#0099ff')
.setTitle(`Shard`)
.setDescription(`## Le serveur est dans la shard N°${currentShard}/${shardMax}\n Ce shard s'occupe de ${totalShardGuilds} serveurs et de ${totalUsers} utilisateurs`);

message.channel.send({ embeds: [defaultEmbed] })
.catch(error => console.error('Erreur lors de l\'envoi du message :', error));

const ping = Date.now() - message.createdTimestamp;
const memoryUsage = process.memoryUsage().heapUsed / 1024 / 1024;
const roundedMemory = Math.round(memoryUsage * 100) / 100;
const roundedping = Math.abs(ping);

const guildId = message.guild.id;
const guildname = message.guild.name;
const username = message.author.username;
const userid = message.author.id;
const shardId = getGuildShardId(message.guild) + 1;

const log = `Commande !shard exécutée en ${roundedping}ms dans (${guildId}) \`${guildname}\` par (${userid}) ${username} dans la shard ${shardId}`;
console.log(log);

const channelId = '1203418114402820146'; // Remplace par l'ID de ton canal
const channel = message.client.channels.cache.get(channelId);
if (channel) {
channel.send(log)
.catch(error => console.error('Erreur lors de l\'envoi du message dans le canal :', error));
} else {
console.error(`Le canal avec l'ID ${channelId} est introuvable.`);
}
},
};
.catch(error => console.error('Erreur lors de l\'envoi du message dans le canal :', error));
} else {
console.error(`Le canal avec l'ID ${channelId} est introuvable.`);
}
},
};
Erreur : Le canal avec l'ID 1203418114402820146 est introuvable. hi duck
duck
duck5mo ago
I imagine that the given channel isn't on the shard you're trying to access it from since this is a hard coded id, I'd assume you also happen to know what guild this channel is in, so you can determine what shard it's actually on with ShardClientUtil.shardIdForGuildId() then you can use <Client>.shard.broadcastEval() (specifying the shard option) to access the channel there
./u.7-z
./u.7-z5mo ago
ah if the command is out on shard 1 we cannot send a message in a channel of shard 2?
duck
duck5mo ago
technically you could using the rest client, but the channel object itself wouldn't be cached on other shards, no
./u.7-z
./u.7-z5mo ago
ah ok thx