Lawa
Lawa
DIAdiscord.js - Imagine a boo! 👻
Created by Lawa on 7/29/2024 in #djs-questions
Cache: FALSE
const content = await imgchannel.send({
files: [{ attachment: url, name: `memex.${extension}` }],
embeds: [embedData],
cache: false,
});
const content = await imgchannel.send({
files: [{ attachment: url, name: `memex.${extension}` }],
embeds: [embedData],
cache: false,
});
simple question. Is cache false here a thing? i can't seem to find documentation on it.
14 replies
DIAdiscord.js - Imagine a boo! 👻
Created by Lawa on 7/24/2024 in #djs-questions
Shard activity
bot.once(Events.ClientReady, async () => {
shardId = bot.shard.ids[0];

bot.user.setActivity({
name: `/help | Shard ${bot.shard.ids[0]}`,
type: ActivityType.Watching,
shardId: bot.shard.ids[0],
});
if (shardId === 0) {
console.log("Started Source");
client.login(process.env.SOURCE_TOKEN);
}
});
bot.once(Events.ClientReady, async () => {
shardId = bot.shard.ids[0];

bot.user.setActivity({
name: `/help | Shard ${bot.shard.ids[0]}`,
type: ActivityType.Watching,
shardId: bot.shard.ids[0],
});
if (shardId === 0) {
console.log("Started Source");
client.login(process.env.SOURCE_TOKEN);
}
});
i aim to set an activity for each individual running shard. the problem with my code is once another shard begins the bot activity is fully gone. how can i achieve my goal?
5 replies
DIAdiscord.js - Imagine a boo! 👻
Created by Lawa on 3/31/2024 in #djs-questions
Memory
hey so, im using chokidar + function to send a message to a channel but everytime i do. Im assuming it caches the attachment sent because, it jumps +8mb of memory everytime the function is called and holds that memory and keeps adding to it when the function is called another time. i have messages cache set to 0 so it cant really cache messages, so why is it using 8mb of memory to send a video and holding the memory hostage 💔 it calls the function every 6 minutes and every 6minutes it adds +8mb to the memory which is an L.
async function sendMedia(receivedFile, mediaChannel) {
try {
const fileName = receivedFile;
const filePath = `${fileName}`;

const embedData = (an embed)

const attachmentToSend = new AttachmentBuilder(filePath);
const content = await mediaChannel.send({
files: [attachmentToSend],
embeds: [embedData],
});
await content.crosspost().catch((error) => console.error(error));

fs.unlink(filePath).catch((error) => console.error(error));
} catch (error) {
console.error(error);
}
}
async function sendMedia(receivedFile, mediaChannel) {
try {
const fileName = receivedFile;
const filePath = `${fileName}`;

const embedData = (an embed)

const attachmentToSend = new AttachmentBuilder(filePath);
const content = await mediaChannel.send({
files: [attachmentToSend],
embeds: [embedData],
});
await content.crosspost().catch((error) => console.error(error));

fs.unlink(filePath).catch((error) => console.error(error));
} catch (error) {
console.error(error);
}
}
24 replies
DIAdiscord.js - Imagine a boo! 👻
Created by Lawa on 3/30/2024 in #djs-questions
Shards
how does sharding work: one shard can have many processes? or one process can have many shards? or one shard has only one process?
const manager = new ShardingManager('./xmain.js', { token: process.env.BOT_TOKEN });

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

manager.spawn();
const manager = new ShardingManager('./xmain.js', { token: process.env.BOT_TOKEN });

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

manager.spawn();
that's what im using
7 replies
DIAdiscord.js - Imagine a boo! 👻
Created by Lawa on 3/29/2024 in #djs-questions
Bot Scaling
As my Discord bot experiences rapid growth and gains traction across a large number of servers, I need to understand the various scaling methods available to ensure seamless performance and handle the increasing load. I have the following questions regarding scaling strategies for my Discord bot built with Discord.js:
Single Server Scalability: Can Discord.js handle scaling my bot to accommodate a vast number of servers while running on a single server instance, or are there inherent limitations that would require a more distributed approach?
Multi-Server Deployment: Is it necessary to deploy my bot across multiple servers to achieve optimal performance and handle the load as the number of servers (guilds) my bot is a part of grows into the millions? If so, what are the best practices and architectures for such a distributed deployment?
Understanding Sharding: Could you provide a detailed explanation of the sharding concept in the context of Discord bots? How does sharding work, and what are the benefits it offers in terms of scalability and resource utilization? In my specific case, with 10GB of RAM and 2 CPU cores available, how would sharding distribute the workload, and would it be possible to configure individual shards with limited RAM allocation (e.g., 512MB per shard) to optimize resource usage?
6 replies
DIAdiscord.js - Imagine a boo! 👻
Created by Lawa on 3/28/2024 in #djs-questions
Subcommands
Hey i have 3 slash commands, setup, setup_image, setup_video, i tried making the setup_image into "setup image" and it worked but the setup command stopped showing. How can i do it while keeping the setup command there?
16 replies
DIAdiscord.js - Imagine a boo! 👻
Created by Lawa on 3/23/2024 in #djs-questions
Caching
Idk what do with caching anymore, I tried sweeping and tbh it doesnt work. I removed the call of messagecontent intents when initializing the bot and it significantly reduced memory usage from 400mb gradually growing over 12h to 190mb graduall growing over 12h both starting at 80mb of ram. So can i disable caching all together? Would that be inefficient. what else can i do here. sweeping is tbh dead. and no i dont have any memory leaks in my code. Or is there a way to sweep all cached stuff by discordjs instead of pointing out every thing to sweep? here is my code rn:
const bot = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildWebhooks,
],
sweepers: {
...Options.DefaultSweeperSettings,
messages: {
interval: 3_600, // Every hour.
lifetime: 1_800, // Remove messages older than 30 minutes.
},
},
});
const bot = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildWebhooks,
],
sweepers: {
...Options.DefaultSweeperSettings,
messages: {
interval: 3_600, // Every hour.
lifetime: 1_800, // Remove messages older than 30 minutes.
},
},
});
38 replies
DIAdiscord.js - Imagine a boo! 👻
Created by Lawa on 3/3/2024 in #djs-questions
[AbortError]: Request aborted
ok so when channel.send(etc...) returns an [AbortError]: Request aborted, it acrtually sends the message up to 3 times sometimes twice the channel. Further more, when channel.send(etc...) is ran and before it sends the message, if i stop the bot and restart it, it will persist sending the message it was sending before i stopped the bot. Why? How do i prevent that? Here is the piece of the code:
const attachmentToSend = new AttachmentBuilder(filePath);
await channel.send({ files: [attachmentToSend] }).catch(error);
const attachmentToSend = new AttachmentBuilder(filePath);
await channel.send({ files: [attachmentToSend] }).catch(error);
3 replies