Nils
Nils
DIAdiscord.js - Imagine an app
Created by Nils on 7/11/2024 in #djs-questions
Sharding not working anymore out of nowhere
Out of nowhere my bot isn't starting anymore, throwing a ShardingReadyDied every time after trying to start the seventh shard. I did not change anything with the host the bot is running on. The complete error looks like this:
error: new Error("Sharding is required")
^
Error: Sharding is required
at WebSocketShard.onClose (/home/container/node_modules/@discordjs/ws/dist/index.js:1114:18)
at connection.onclose (/home/container/node_modules/@discordjs/ws/dist/index.js:676:17)
at callListener (/home/container/node_modules/ws/lib/event-target.js:290:14)
at WebSocket.onClose (/home/container/node_modules/ws/lib/event-target.js:220:9)
at WebSocket.emit (node:events:519:28)
at WebSocket.emitClose (/home/container/node_modules/ws/lib/websocket.js:260:10)
at TLSSocket.socketOnClose (/home/container/node_modules/ws/lib/websocket.js:1272:15)
at TLSSocket.emit (node:events:531:35)
at node:net:338:12
at TCP.done (node:_tls_wrap:657:7)
Node.js v20.15.0
[11/07/2024-16:59:02.879] [ERROR] /home/container/node_modules/discord.js/src/sharding/Shard.js:178
reject(new DiscordjsError(ErrorCodes.ShardingReadyDied, this.id));
^
[11/07/2024-16:59:02.884] [ERROR] Error [ShardingReadyDied]: Shard 7's process exited before its Client became ready.
at Shard.onDeath (/home/container/node_modules/discord.js/src/sharding/Shard.js:178:16)
at Object.onceWrapper (node:events:634:26)
at Shard.emit (node:events:519:28)
at Shard.emit (node:domain:488:12)
at Shard._handleExit (/home/container/node_modules/discord.js/src/sharding/Shard.js:439:10)
at ChildProcess.emit (node:events:519:28)
at ChildProcess.emit (node:domain:488:12)
at Process.ChildProcess._handle.onexit (node:internal/child_process:294:12) {
code: 'ShardingReadyDied'
}
error: new Error("Sharding is required")
^
Error: Sharding is required
at WebSocketShard.onClose (/home/container/node_modules/@discordjs/ws/dist/index.js:1114:18)
at connection.onclose (/home/container/node_modules/@discordjs/ws/dist/index.js:676:17)
at callListener (/home/container/node_modules/ws/lib/event-target.js:290:14)
at WebSocket.onClose (/home/container/node_modules/ws/lib/event-target.js:220:9)
at WebSocket.emit (node:events:519:28)
at WebSocket.emitClose (/home/container/node_modules/ws/lib/websocket.js:260:10)
at TLSSocket.socketOnClose (/home/container/node_modules/ws/lib/websocket.js:1272:15)
at TLSSocket.emit (node:events:531:35)
at node:net:338:12
at TCP.done (node:_tls_wrap:657:7)
Node.js v20.15.0
[11/07/2024-16:59:02.879] [ERROR] /home/container/node_modules/discord.js/src/sharding/Shard.js:178
reject(new DiscordjsError(ErrorCodes.ShardingReadyDied, this.id));
^
[11/07/2024-16:59:02.884] [ERROR] Error [ShardingReadyDied]: Shard 7's process exited before its Client became ready.
at Shard.onDeath (/home/container/node_modules/discord.js/src/sharding/Shard.js:178:16)
at Object.onceWrapper (node:events:634:26)
at Shard.emit (node:events:519:28)
at Shard.emit (node:domain:488:12)
at Shard._handleExit (/home/container/node_modules/discord.js/src/sharding/Shard.js:439:10)
at ChildProcess.emit (node:events:519:28)
at ChildProcess.emit (node:domain:488:12)
at Process.ChildProcess._handle.onexit (node:internal/child_process:294:12) {
code: 'ShardingReadyDied'
}
16 replies
DIAdiscord.js - Imagine an app
Created by Nils on 11/16/2023 in #djs-questions
Memory leak in discord js
I am currently facing a problem with a memory leak. I don't quite think it's related to discord.js, nevertheless I would like to ask if there are any common mistakes you can make with discord.js that lead to a memory leak. Or are there any other known problems with discord.js that lead to memory leaks?
19 replies
DIAdiscord.js - Imagine an app
Created by Nils on 11/14/2023 in #djs-questions
Sharding times out after several other shards launched successfully
Good afternoon everybody, I'm currently stuck with a sharding problem that only occurs on my external VPS. At the moment I can't really differenciate if it is because of said VPS or if it is problem with discord.js, that's why I'm here as my last option of help. When running the bot on my local computer everything works just fine. Every shard launches correctly and is ready to use afterwards. Now I tried to migrate everything to a VPS to try to put the bot into operation. The problem now is that after several shards launched successfully, the next one times out and I get the following error:
Error [ShardingReadyTimeout]: Shard 45's Client took too long to become ready.
at Timeout.onTimeout (/home/container/node_modules/discord.js/src/sharding/Shard.js:183:16)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7) {
code: 'ShardingReadyTimeout'
}
Error [ShardingReadyTimeout]: Shard 45's Client took too long to become ready.
at Timeout.onTimeout (/home/container/node_modules/discord.js/src/sharding/Shard.js:183:16)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7) {
code: 'ShardingReadyTimeout'
}
My sharding manager looks like this:
const { ShardingManager } = require('discord.js');

require('dotenv').config();

const manager = new ShardingManager('./bot.js', { token: process.env.TOKEN, respawn: true });

manager.on('shardCreate', shard => console.log(`Shard ${shard.id} launching...`));

manager.spawn({ delay: 1500, timeout: 30000 }).catch(error => console.log(error));
const { ShardingManager } = require('discord.js');

require('dotenv').config();

const manager = new ShardingManager('./bot.js', { token: process.env.TOKEN, respawn: true });

manager.on('shardCreate', shard => console.log(`Shard ${shard.id} launching...`));

manager.spawn({ delay: 1500, timeout: 30000 }).catch(error => console.log(error));
I hope someone finds the solution to this, thanks in advance!
9 replies
DIAdiscord.js - Imagine an app
Created by Nils on 7/13/2022 in #djs-questions
MessageAttachement isn't working
Hi, I'm trying to add a local file to my embed but it is giving me an Invalid Form Body error: Scheme "attachement" is not supported. Scheme must be one of ('http', 'https').. My code looks like the following:
const { MessageEmbed, MessageAttachment } = require("discord.js");
const countries = require("svg-country-flags/countries.json");

module.exports = {
data: new SlashCommandBuilder()
.setName("guess")
.setDescription("Guess a random flag"),


async execute(interaction) {

let randomProperty = function (obj) {
let keys = Object.keys(obj);
let num = keys.length * Math.random() << 0;

return `${keys[num]}, ${obj[keys[num]]}`;
};


let randCountry = randomProperty(countries);
randCountry = randCountry.split(", ");

const file = new MessageAttachment(`./node_modules/svg-country-flags/png1000px/${randCountry[0]}.png`);

const guessEmbed = new MessageEmbed()
.setColor("GREEN")
.setTitle("Guess that Flag!")
.setDescription(`<t:${countdown}:R>`)
.setImage({
url: `attachement://${randCountry[0]}.png`,
size: 256
})

interaction.reply({ embeds: [guessEmbed], files: [file] })

};

};
const { MessageEmbed, MessageAttachment } = require("discord.js");
const countries = require("svg-country-flags/countries.json");

module.exports = {
data: new SlashCommandBuilder()
.setName("guess")
.setDescription("Guess a random flag"),


async execute(interaction) {

let randomProperty = function (obj) {
let keys = Object.keys(obj);
let num = keys.length * Math.random() << 0;

return `${keys[num]}, ${obj[keys[num]]}`;
};


let randCountry = randomProperty(countries);
randCountry = randCountry.split(", ");

const file = new MessageAttachment(`./node_modules/svg-country-flags/png1000px/${randCountry[0]}.png`);

const guessEmbed = new MessageEmbed()
.setColor("GREEN")
.setTitle("Guess that Flag!")
.setDescription(`<t:${countdown}:R>`)
.setImage({
url: `attachement://${randCountry[0]}.png`,
size: 256
})

interaction.reply({ embeds: [guessEmbed], files: [file] })

};

};
6 replies
DIAdiscord.js - Imagine an app
Created by Nils on 6/28/2022 in #djs-questions
.awaitMessages isn't working
Hi, I'm currently trying to make a quiz where you have to guess a random member of a guild by it's profile picture. Therefore I made this command
const { SlashCommandBuilder } = require("@discordjs/builders");
const { MessageEmbed } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName("guess")
.setDescription("Guess a random member of the server by the profile picture"),

async execute(interaction) {

const guildMembers = await interaction.guild.members.fetch();
const randMember = guildMembers.random();

const member = randMember.displayName;

const guessEmbed = new MessageEmbed()
.setColor(randMember.user.accentColor)
.setTitle("Guess that Member!")
.setImage(`${randMember.displayAvatarURL()}`)
.setFooter({text: "developed by Nils#7168"})


//console.log(randMember.displayName)

interaction.reply({ embeds: [guessEmbed], fetchReply: true })
.then(() => {
interaction.channel.awaitMessages({ member, max: 1, time: 15000, errors: ['time'] })
.then(collected => {
interaction.followUp(`<@${collected.first().author.id}> you're right! It was ${member}.`);
})
.catch(collected => {
interaction.followUp(`Looks like nobody got the right answer. It was ${member}.`);
});
});



},
};
const { SlashCommandBuilder } = require("@discordjs/builders");
const { MessageEmbed } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName("guess")
.setDescription("Guess a random member of the server by the profile picture"),

async execute(interaction) {

const guildMembers = await interaction.guild.members.fetch();
const randMember = guildMembers.random();

const member = randMember.displayName;

const guessEmbed = new MessageEmbed()
.setColor(randMember.user.accentColor)
.setTitle("Guess that Member!")
.setImage(`${randMember.displayAvatarURL()}`)
.setFooter({text: "developed by Nils#7168"})


//console.log(randMember.displayName)

interaction.reply({ embeds: [guessEmbed], fetchReply: true })
.then(() => {
interaction.channel.awaitMessages({ member, max: 1, time: 15000, errors: ['time'] })
.then(collected => {
interaction.followUp(`<@${collected.first().author.id}> you're right! It was ${member}.`);
})
.catch(collected => {
interaction.followUp(`Looks like nobody got the right answer. It was ${member}.`);
});
});



},
};
It fetches all members of a guild, picks a random member out of the collection and sends the profile picture with a embed. Then I want to await the Message with the username of the member. Now that's the point that isn't working. Although it sends the username of the member after the 15000ms passed, the bot isn't responding when I send a message with the correct username. It seems like the filter, in my case the member variable isn't working. Why?
6 replies
DIAdiscord.js - Imagine an app
Created by Nils on 6/24/2022 in #djs-questions
Error when creating Channel
Hi, I'm currently trying to do a support ticket bot. Sadly I'm getting the following problem HTTPError [TypeError] Do not know how to serialize a BigInt. My Code is
const ticketEmbed = new MessageEmbed()
.setColor("#7289da")
.setTitle(`${interaction.member.nickname}: ${ticketReason}`)
.addFields(
{ name: `${languagePath.ticket_explanation}`, value: `${ticketExplanation}` },
{ name: `${languagePath.ticket_additional}`, value: `${ticketOther}`}
)
.setFooter({ text: `${languagePath.credits}` });

interaction.guild.channels.create({
name: "ticket - " + interaction.member.nickname,
type: "GUILD_TEXT",
permissionOverwrites: [
{
id: interaction.guild.id,
deny: [Permissions.FLAGS.VIEW_CHANNEL],
},
{
id: interaction.member.id,
allow: [Permissions.FLAGS.VIEW_CHANNEL],
},
{
id: supportRoleID,
allow: [Permissions.FLAGS.VIEW_CHANNEL],
}
]
}).then( channel => {
channel.send({ embeds: [ticketEmbed]})
})
const ticketEmbed = new MessageEmbed()
.setColor("#7289da")
.setTitle(`${interaction.member.nickname}: ${ticketReason}`)
.addFields(
{ name: `${languagePath.ticket_explanation}`, value: `${ticketExplanation}` },
{ name: `${languagePath.ticket_additional}`, value: `${ticketOther}`}
)
.setFooter({ text: `${languagePath.credits}` });

interaction.guild.channels.create({
name: "ticket - " + interaction.member.nickname,
type: "GUILD_TEXT",
permissionOverwrites: [
{
id: interaction.guild.id,
deny: [Permissions.FLAGS.VIEW_CHANNEL],
},
{
id: interaction.member.id,
allow: [Permissions.FLAGS.VIEW_CHANNEL],
},
{
id: supportRoleID,
allow: [Permissions.FLAGS.VIEW_CHANNEL],
}
]
}).then( channel => {
channel.send({ embeds: [ticketEmbed]})
})
Also when I comment out the permissionOverwrites I get a different Error DiscordAPIError: Invalid Form Body, name: Could not interpret "{'name': 'ticket - null', 'type': 'GUILD_TEXT'}" as string.. I suppose that the options I set for the channel are somehow misinterpreted into strings, but why?
4 replies
DIAdiscord.js - Imagine an app
Created by Nils on 6/20/2022 in #djs-questions
Get Message a button is attached to
Hey, I have a button which is attached to a normal message. When I click the button I want to get the message the button is attached to. How do I do this? I appreciate any help.
3 replies