🗿Patryk🍷
🗿Patryk🍷
DIAdiscord.js - Imagine an app
Created by logic on 11/18/2024 in #djs-questions
Memory leak when sharding
But after just 3 days 180mb
10 replies
DIAdiscord.js - Imagine an app
Created by logic on 11/18/2024 in #djs-questions
Memory leak when sharding
I also have this problem. After starting the bot with sharding about 85mb and after about 2 days 120mb
10 replies
DIAdiscord.js - Imagine an app
Created by 🗿Patryk🍷 on 11/18/2024 in #djs-voice
encryption does not work
-------------------------------------------------- Core Dependencies - @discordjs/voice: 0.18.0 - prism-media: 1.3.5 Opus Libraries - @discordjs/opus: 0.9.0 - opusscript: 0.0.8 Encryption Libraries - sodium-native: 3.4.1 - sodium: not found - libsodium-wrappers: 0.7.15 - @stablelib/xchacha20poly1305: not found - @noble/ciphers: not found FFmpeg - version: 6.0-static https://johnvansickle.com/ffmpeg/ - libopus: yes --------------------------------------------------
3 replies
DIAdiscord.js - Imagine an app
Created by 🗿Patryk🍷 on 9/21/2024 in #djs-questions
Shard info
But I already want to know how to do it
7 replies
DIAdiscord.js - Imagine an app
Created by 🗿Patryk🍷 on 9/21/2024 in #djs-questions
Shard info
So far I'm just testing
7 replies
DIAdiscord.js - Imagine an app
Created by 🗿Patryk🍷 on 9/21/2024 in #djs-questions
Shard info
const { SlashCommandBuilder } = require('@discordjs/builders');
const { EmbedBuilder } = require('discord.js');
const { client } = require('../index.js'); // Import klienta

module.exports = {
data: new SlashCommandBuilder()
.setName('shard')
.setDescription('Wyświetla informacje o shardach'),
async execute(interaction) {
if (!interaction.deferred && !interaction.replied) {
await interaction.deferReply();
}

try {
// Fetch the guild counts for each shard
const guildCounts = await client.shard.fetchClientValues('guilds.cache.size');
const totalGuildCount = guildCounts.reduce((acc, count) => acc + count, 0);

// Get stats for each shard
const shardStats = await client.shard.broadcastEval(c => {
return {
shardId: c.shard.id,
guildCount: c.guilds.cache.size,
ping: c.ws.ping >= 0 ? c.ws.ping : 'N/A', // Używamy 'N/A' zamiast -1
uptime: c.uptime,
memoryUsage: process.memoryUsage().heapUsed / 1024 / 1024 // Użycie pamięci w MB
};
});

// Create embed with shard information
const embed = new EmbedBuilder()
.setColor('#0099ff')
.setTitle('Informacje o shardach')
.addFields({
name: 'Łączna liczba serwerów:',
value: `${totalGuildCount}`,
inline: false
});

shardStats.forEach(stat => {
embed.addFields({
name: `Shard ID: ${stat.shardId}`,
value: `Liczba serwerów: ${stat.guildCount}\nPing: ${stat.ping} ms\nCzas działania: ${Math.floor(stat.uptime / 1000)} sekundy\nUżycie pamięci: ${Math.round(stat.memoryUsage * 100) / 100} MB`,
inline: false
});
});

await interaction.editReply({ embeds: [embed] });
} catch (error) {
console.error(error);
await interaction.editReply('Wystąpił błąd podczas pobierania informacji o shardach.');
}
},
};
const { SlashCommandBuilder } = require('@discordjs/builders');
const { EmbedBuilder } = require('discord.js');
const { client } = require('../index.js'); // Import klienta

module.exports = {
data: new SlashCommandBuilder()
.setName('shard')
.setDescription('Wyświetla informacje o shardach'),
async execute(interaction) {
if (!interaction.deferred && !interaction.replied) {
await interaction.deferReply();
}

try {
// Fetch the guild counts for each shard
const guildCounts = await client.shard.fetchClientValues('guilds.cache.size');
const totalGuildCount = guildCounts.reduce((acc, count) => acc + count, 0);

// Get stats for each shard
const shardStats = await client.shard.broadcastEval(c => {
return {
shardId: c.shard.id,
guildCount: c.guilds.cache.size,
ping: c.ws.ping >= 0 ? c.ws.ping : 'N/A', // Używamy 'N/A' zamiast -1
uptime: c.uptime,
memoryUsage: process.memoryUsage().heapUsed / 1024 / 1024 // Użycie pamięci w MB
};
});

// Create embed with shard information
const embed = new EmbedBuilder()
.setColor('#0099ff')
.setTitle('Informacje o shardach')
.addFields({
name: 'Łączna liczba serwerów:',
value: `${totalGuildCount}`,
inline: false
});

shardStats.forEach(stat => {
embed.addFields({
name: `Shard ID: ${stat.shardId}`,
value: `Liczba serwerów: ${stat.guildCount}\nPing: ${stat.ping} ms\nCzas działania: ${Math.floor(stat.uptime / 1000)} sekundy\nUżycie pamięci: ${Math.round(stat.memoryUsage * 100) / 100} MB`,
inline: false
});
});

await interaction.editReply({ embeds: [embed] });
} catch (error) {
console.error(error);
await interaction.editReply('Wystąpił błąd podczas pobierania informacji o shardach.');
}
},
};
7 replies
DIAdiscord.js - Imagine an app
Created by 🗿Patryk🍷 on 9/12/2024 in #djs-questions
registering commands
I did everything right I just have a rate limit
33 replies
DIAdiscord.js - Imagine an app
Created by 🗿Patryk🍷 on 9/12/2024 in #djs-questions
registering commands
I have a synchronous function and I can see that the registration starts but does not end because the status change function does not start
33 replies
DIAdiscord.js - Imagine an app
Created by 🗿Patryk🍷 on 9/12/2024 in #djs-questions
registering commands
Maybe I have a rate limit?
33 replies
DIAdiscord.js - Imagine an app
Created by 🗿Patryk🍷 on 9/12/2024 in #djs-questions
registering commands
Commands don't register
33 replies
DIAdiscord.js - Imagine an app
Created by 🗿Patryk🍷 on 9/12/2024 in #djs-questions
registering commands
But I don't see the ending
33 replies
DIAdiscord.js - Imagine an app
Created by 🗿Patryk🍷 on 9/12/2024 in #djs-questions
registering commands
Rozpoczęto odświeżanie 80 komend aplikacji (/)
Rozpoczęto odświeżanie 80 komend aplikacji (/)
33 replies
DIAdiscord.js - Imagine an app
Created by 🗿Patryk🍷 on 9/12/2024 in #djs-questions
registering commands
Unfortunately it still doesn't work
33 replies
DIAdiscord.js - Imagine an app
Created by 🗿Patryk🍷 on 9/12/2024 in #djs-questions
registering commands
// Funkcja do rejestracji komend globalnych
async function registerGlobalCommands(client) {
console.log("Rozpoczynam rejestrację komend globalnych...");

const commandsToSet = [];

// Przygotowanie komend do zarejestrowania
for (const command of client.commands.values()) {
if (!command || !command.data) {
console.warn(`Pominięto nieprawidłową komendę: ${command}`);
continue;
}
commandsToSet.push(command.data.toJSON());
}

// Inicjalizuj REST API z tokenem
const rest = new REST().setToken(token);

try {
console.log(`Rozpoczęto odświeżanie ${commandsToSet.length} komend aplikacji (/)`);

// Rejestruj komendy globalnie
const data = await rest.put(
Routes.applicationCommands(clientId), // Rejestracja globalna komend
{ body: commandsToSet },
);

console.log(`Pomyslnie odświeżono ${data.length} komend aplikacji (/)`);

// Wypisanie zarejestrowanych komend
console.log("Obecnie zarejestrowane komendy globalne:");
data.forEach(cmd => console.log(`- ${cmd.name}`));
} catch (error) {
console.error('Błąd podczas rejestracji komend globalnych:', error);
}
}
// Funkcja do rejestracji komend globalnych
async function registerGlobalCommands(client) {
console.log("Rozpoczynam rejestrację komend globalnych...");

const commandsToSet = [];

// Przygotowanie komend do zarejestrowania
for (const command of client.commands.values()) {
if (!command || !command.data) {
console.warn(`Pominięto nieprawidłową komendę: ${command}`);
continue;
}
commandsToSet.push(command.data.toJSON());
}

// Inicjalizuj REST API z tokenem
const rest = new REST().setToken(token);

try {
console.log(`Rozpoczęto odświeżanie ${commandsToSet.length} komend aplikacji (/)`);

// Rejestruj komendy globalnie
const data = await rest.put(
Routes.applicationCommands(clientId), // Rejestracja globalna komend
{ body: commandsToSet },
);

console.log(`Pomyslnie odświeżono ${data.length} komend aplikacji (/)`);

// Wypisanie zarejestrowanych komend
console.log("Obecnie zarejestrowane komendy globalne:");
data.forEach(cmd => console.log(`- ${cmd.name}`));
} catch (error) {
console.error('Błąd podczas rejestracji komend globalnych:', error);
}
}
33 replies
DIAdiscord.js - Imagine an app
Created by 🗿Patryk🍷 on 9/12/2024 in #djs-questions
registering commands
Do I have to do this or can it be done without it?
33 replies
DIAdiscord.js - Imagine an app
Created by 🗿Patryk🍷 on 9/12/2024 in #djs-questions
registering commands
and now:
Error: ENOTDIR: not a directory, scandir '/home/container/commands/8ball.js'
at Object.readdirSync (node:fs:1508:26)
at Object.<anonymous> (/home/container/register.js:14:26)
at Module._compile (node:internal/modules/cjs/loader:1368:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1426:10)
at Object.require.extensions.<computed> [as .js] (/usr/local/lib/node_modules/ts-node/src/index.ts:1608:43)
at Module.load (node:internal/modules/cjs/loader:1205:32)
at Function.Module._load (node:internal/modules/cjs/loader:1021:12)
at cjsLoader (node:internal/modules/esm/translators:366:17)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:315:7)
at ModuleJob.run (node:internal/modules/esm/module_job:222:25) {
errno: -20,
code: 'ENOTDIR',
syscall: 'scandir',
path: '/home/container/commands/8ball.js'
}
Error: ENOTDIR: not a directory, scandir '/home/container/commands/8ball.js'
at Object.readdirSync (node:fs:1508:26)
at Object.<anonymous> (/home/container/register.js:14:26)
at Module._compile (node:internal/modules/cjs/loader:1368:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1426:10)
at Object.require.extensions.<computed> [as .js] (/usr/local/lib/node_modules/ts-node/src/index.ts:1608:43)
at Module.load (node:internal/modules/cjs/loader:1205:32)
at Function.Module._load (node:internal/modules/cjs/loader:1021:12)
at cjsLoader (node:internal/modules/esm/translators:366:17)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:315:7)
at ModuleJob.run (node:internal/modules/esm/module_job:222:25) {
errno: -20,
code: 'ENOTDIR',
syscall: 'scandir',
path: '/home/container/commands/8ball.js'
}
33 replies
DIAdiscord.js - Imagine an app
Created by 🗿Patryk🍷 on 9/12/2024 in #djs-questions
registering commands
const { REST, Routes } = require('discord.js');
const { clientId, guildId, token } = require('./config.json');
const fs = require('node:fs');
const path = require('node:path');

const commands = [];
// Grab all the command folders from the commands directory you created earlier
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);

for (const folder of commandFolders) {
// Grab all the command files from the commands directory you created earlier
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}

// Construct and prepare an instance of the REST module
const rest = new REST().setToken(token);

// and deploy your commands!
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);

// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationCommands(clientId),
{ body: commands },
);

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();
const { REST, Routes } = require('discord.js');
const { clientId, guildId, token } = require('./config.json');
const fs = require('node:fs');
const path = require('node:path');

const commands = [];
// Grab all the command folders from the commands directory you created earlier
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);

for (const folder of commandFolders) {
// Grab all the command files from the commands directory you created earlier
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}

// Construct and prepare an instance of the REST module
const rest = new REST().setToken(token);

// and deploy your commands!
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);

// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationCommands(clientId),
{ body: commands },
);

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();
33 replies
DIAdiscord.js - Imagine an app
Created by 🗿Patryk🍷 on 9/12/2024 in #djs-questions
registering commands
why 0
33 replies
DIAdiscord.js - Imagine an app
Created by 🗿Patryk🍷 on 9/12/2024 in #djs-questions
registering commands
Started refreshing 0 application (/) commands. Successfully reloaded 0 application (/) commands.
33 replies
DIAdiscord.js - Imagine an app
Created by 🗿Patryk🍷 on 9/12/2024 in #djs-questions
registering commands
old script
// Funkcja do rejestracji komend globalnych
async function registerGlobalCommands(client) {
console.log("Rozpoczynam rejestrację komend globalnych...");
const commandsToSet = [];

for (const command of client.commands.values()) {
if (!command || !command.data) {
console.warn(`Pominięto nieprawidłową komendę: ${command}`);
continue;
}
commandsToSet.push(command.data.toJSON());
}

try {
// Użycie metody set() nadpisze wszystkie istniejące komendy
const setCommands = await client.application.commands.set(commandsToSet);
console.log(`Zarejestrowano ${setCommands.size} komend globalnie.`);

// Wypisanie zarejestrowanych komend
console.log("Obecnie zarejestrowane komendy globalne:");
setCommands.forEach(cmd => console.log(`- ${cmd.name}`));
} catch (error) {
console.error(`Błąd podczas rejestracji komend globalnych:`, error);
}
}
// Funkcja do rejestracji komend globalnych
async function registerGlobalCommands(client) {
console.log("Rozpoczynam rejestrację komend globalnych...");
const commandsToSet = [];

for (const command of client.commands.values()) {
if (!command || !command.data) {
console.warn(`Pominięto nieprawidłową komendę: ${command}`);
continue;
}
commandsToSet.push(command.data.toJSON());
}

try {
// Użycie metody set() nadpisze wszystkie istniejące komendy
const setCommands = await client.application.commands.set(commandsToSet);
console.log(`Zarejestrowano ${setCommands.size} komend globalnie.`);

// Wypisanie zarejestrowanych komend
console.log("Obecnie zarejestrowane komendy globalne:");
setCommands.forEach(cmd => console.log(`- ${cmd.name}`));
} catch (error) {
console.error(`Błąd podczas rejestracji komend globalnych:`, error);
}
}
33 replies