vivian <3
vivian <3
DIAdiscord.js - Imagine an app
Created by vivian <3 on 8/7/2024 in #djs-questions
pass variables into <ShardClientUtil>.broadcastEval()
I've got the following code:
var commandName = `foo`;

await client.shard.broadcastEval(async (c) => {

delete require.cache[require.resolve(`../${commandName}.js`)];
});
var commandName = `foo`;

await client.shard.broadcastEval(async (c) => {

delete require.cache[require.resolve(`../${commandName}.js`)];
});
how would i modify the function to include var commandName inside of broadcastEval() ?
4 replies
DIAdiscord.js - Imagine an app
Created by vivian <3 on 6/5/2023 in #djs-questions
waiting for interaction collector to finish before executing another function
code:
await interaction.reply({ ephemeral: false, embeds: [embed], components: [row] }).catch(e => console.log(e));

let filter = i => [`next`, `exit`].includes(i.customId);
let collector = await interaction.channel.createMessageComponentCollector({ filter, max: 1, time: 20000 });
let endCon = 0;

collector.on('collect', async i => {
await i.deferUpdate();

if (i.customId === `next`) {
endCon = 1;
collector.emit('end', collected => { });
}
else if (i.customId === `exit`) {
collector.emit('end', collected => { });
}
else {
collector.emit('end', collected => { });
}
});

collector.on('end', async collected => {
if (endCon == 0) {
await interaction.editReply({ content: `Command exited/timed out. Please use this command again.`, components: [], embeds: [] }).catch(e => console.log(e));
} else {
await interaction.editReply({ content: `Continuing`, components: [], embeds: [] }).catch(e => console.log(e));
};
});

for (let i = 0; i < challengeData.story.length; i++) {
// to be implemented
}

await interaction.followUp(`This command is currently a work in progress.`);
await interaction.reply({ ephemeral: false, embeds: [embed], components: [row] }).catch(e => console.log(e));

let filter = i => [`next`, `exit`].includes(i.customId);
let collector = await interaction.channel.createMessageComponentCollector({ filter, max: 1, time: 20000 });
let endCon = 0;

collector.on('collect', async i => {
await i.deferUpdate();

if (i.customId === `next`) {
endCon = 1;
collector.emit('end', collected => { });
}
else if (i.customId === `exit`) {
collector.emit('end', collected => { });
}
else {
collector.emit('end', collected => { });
}
});

collector.on('end', async collected => {
if (endCon == 0) {
await interaction.editReply({ content: `Command exited/timed out. Please use this command again.`, components: [], embeds: [] }).catch(e => console.log(e));
} else {
await interaction.editReply({ content: `Continuing`, components: [], embeds: [] }).catch(e => console.log(e));
};
});

for (let i = 0; i < challengeData.story.length; i++) {
// to be implemented
}

await interaction.followUp(`This command is currently a work in progress.`);
discord.js v14.11.0 node.js v16.17.0 Goal: Have the interaction.followUp() statement run after MessageComponentCollector is finished collecting. What's happening currently: interaction.reply() and interaction.followUp() run right after the other, without waiting for the collector to finish
6 replies
DIAdiscord.js - Imagine an app
Created by vivian <3 on 6/1/2023 in #djs-questions
sharding across multiple cores
IIRC, Discord.js's native ShardingManager only distributes shards across a single core (as far as v14.11.0 goes). I've looked into Kurasuta, a sharding manager that allows for shard distribution across multiple cores. Can anyone recommend Kurasuta, or a different manager?
2 replies
DIAdiscord.js - Imagine an app
Created by vivian <3 on 6/1/2023 in #djs-questions
'sharding is required' error, with sharding
recently upgraded to the latest version of discord.js. using the default ShardingManager that djs offers, but when I start up my bot, i still spontaneously get errors of "Error: Sharding is required" from the websocket.js file (context: 45 shards, ~104,500 servers, djs v14.11.0, node.js v16.17.0)
9 replies
DIAdiscord.js - Imagine an app
Created by vivian <3 on 4/24/2023 in #djs-questions
checking server boosters without roles
Is there a way to check if a user is server boosting a server without having to check roles. (and is there a way to check how many boosts a user has on said server at once?)
6 replies
DIAdiscord.js - Imagine an app
Created by vivian <3 on 3/12/2023 in #djs-questions
How do I wait for a Collector to finish before executing lines below?
The issue is that "finish" (at the bottom of the code) is being logged before the collector finishes. How do I make the program wait for the collector to finish before continuing?
let comArr = [`slice`, `call`, `walk`];
let actionVal = 0;

await msg.edit({ ephemeral: false, embeds: [embed], components: [buttonArr] });

let filter = m => comArr.includes(m.customId) && m.user.id == message.author.id;
let collector = await message.channel.createMessageComponentCollector({ componentType: Discord.ComponentType.Button, filter, time: 15000 });

collector.on('collect', async i => {
await i.deferUpdate();
await n.sleep(50);
console.log(i.customId)
if (i.customId == `slice`) {
actionVal = 1;
collector.emit('end', collected => { });
} else if (i.customId == `call`) {
actionVal = 2;
collector.emit('end', collected => { });
} else if (i.customId == `walk`) {
actionVal = 3;
collector.emit('end', collected => { });
} else {
collector.emit('end', collected => { });
}

});

// end collector event
collector.on('end', async collected => {
console.log(actionVal)

let embed3 = new Discord.EmbedBuilder()
.setColor(`${n.color()}`)
.setTitle(`test`)
});

await msg.edit({ ephemeral: false, embeds: [embed3], components: [] });
});

await n.sleep(5000);
console.log(`finish`)
let comArr = [`slice`, `call`, `walk`];
let actionVal = 0;

await msg.edit({ ephemeral: false, embeds: [embed], components: [buttonArr] });

let filter = m => comArr.includes(m.customId) && m.user.id == message.author.id;
let collector = await message.channel.createMessageComponentCollector({ componentType: Discord.ComponentType.Button, filter, time: 15000 });

collector.on('collect', async i => {
await i.deferUpdate();
await n.sleep(50);
console.log(i.customId)
if (i.customId == `slice`) {
actionVal = 1;
collector.emit('end', collected => { });
} else if (i.customId == `call`) {
actionVal = 2;
collector.emit('end', collected => { });
} else if (i.customId == `walk`) {
actionVal = 3;
collector.emit('end', collected => { });
} else {
collector.emit('end', collected => { });
}

});

// end collector event
collector.on('end', async collected => {
console.log(actionVal)

let embed3 = new Discord.EmbedBuilder()
.setColor(`${n.color()}`)
.setTitle(`test`)
});

await msg.edit({ ephemeral: false, embeds: [embed3], components: [] });
});

await n.sleep(5000);
console.log(`finish`)
3 replies
DIAdiscord.js - Imagine an app
Created by vivian <3 on 1/10/2023 in #djs-questions
transfer ownership from bot to user
how do you have a bot transfer ownership of a server to a user? I don't know how, but one of my users managed to make my bot the owner of their server. i'd like to undo that. (a mod told me in the Discord Developers server that this is only possible when the bot is in 10 servers or less, but my bot is in 100,000+ servers) i didn't know any of this was possible, so i'm not sure if this is built into discord.js
4 replies
DIAdiscord.js - Imagine an app
Created by vivian <3 on 12/7/2022 in #djs-questions
How often should client.user.setActivity() be used?
I currently set it to reset the activity every 10 minutes, but what's the max length of time I can set it to (while maintaining a constant status)?
18 replies
DIAdiscord.js - Imagine an app
Created by vivian <3 on 9/5/2022 in #djs-questions
running a Discord bot on multiple hosts
Is there a way to run a Discord bot on multiple hosts? I now have access to two host servers, and would like to be able to run 50 shards of my bot on one host and the last 50 shards of my bot on the second host. Are there any tutorials to go about this? I have not found any.
4 replies
DIAdiscord.js - Imagine an app
Created by vivian <3 on 9/4/2022 in #djs-questions
Discord.js stylesheets
I'm prepping some Discord bot code for public release on Github. Are there any official Discord.js stylesheets available to organize the code in a specific way, or are developers encouraged to pioneer their own style of file and code organization?
3 replies