Non-Sharded Functions #10573
Unanswered
Legends-of-NGDB
asked this question in
Q&A
Replies: 2 comments 1 reply
-
My reaction event also is running on shards when I'm using broadcastEval. This probably is why I'm encountering it const ngdb = require(`./../@ngdb`);
const reactions = require(`./../Schemas/react.js`);
module.exports = async (client, reaction, user) => {
console.log(reaction.message.guild)
if (user.bot || !reaction.message.guildId) return;
ngdb.AddBuilder(client, reaction, user);
return reactionRole(client, reaction, user);
}
async function reactionRole(client, reaction, user) {
try {
let emoji;
if (reaction.emoji.id) {
// Custom emoji
emoji = `<:${reaction.emoji.name}:${reaction.emoji.id}>`;
} else {
// Unicode emoji
emoji = reaction.emoji.name;
}
const data = await reactions.findOne({ Guild: reaction.message.guildId, Message: reaction.message.id, Emoji: emoji });
if (!data) return;
const guildEval = reaction.message.guildId;
const shardId = Discord.ShardClientUtil.shardIdForGuildId(guildEval, client.shard.count);
client.shard.broadcastEval(
async (c, { guildEval }) => {
if (c.guilds.cache.has(guildEval)) {
const guild = await c.guilds.fetch(guildEval)
const member = await guild.members.cache.get(user.id);
try {
await member.roles.add(data.Role);
} catch (e) {
return;
}
}
},
{
context: { guildEval },
shard: shardId
})
} catch (e) {
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
This comment was marked as spam.
This comment was marked as spam.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello again. I think I have discovered in my other discussion why I'm sometimes hitting the rate limit for broadcastEval, but not totally.
These are function that I call for broadcastEval() and they are happening in my bot.js so every shard is calling them. This is very unnecessary as the function to run on its own shard. I haven't reached 2500 guilds yet, but is there a work around without a discord.js error about sharding? I was thinking something like this:
Would this example work?
Beta Was this translation helpful? Give feedback.
All reactions