shard.broadcastEval gives me a reference error even tho all vars are defined

So I just sharded my bot and was playing around with client.broadcastEval and it gives me this. got a channelCreate.js event file like so:
module.exports = async (Discord, client, newChannel) => {
let logC;
console.log(newChannel.guild.name);
client.shard.broadcastEval(
async (c, { channelId }) => {
logC = await c.channels.fetch(channelId);
if (logC) {
logC = logC;
return true;
}
},
{ context: { channelId: "1061724696493703248" } }
);
logC.send("SHARD GOOD");
};
module.exports = async (Discord, client, newChannel) => {
let logC;
console.log(newChannel.guild.name);
client.shard.broadcastEval(
async (c, { channelId }) => {
logC = await c.channels.fetch(channelId);
if (logC) {
logC = logC;
return true;
}
},
{ context: { channelId: "1061724696493703248" } }
);
logC.send("SHARD GOOD");
};
and it gives this error when a channel is created
node:internal/process/promises:246
triggerUncaughtException(err, true /* fromPromise */);
^

Error [ReferenceError]: newChannel is not defined
at eval (eval at _eval (C:\Users\ddmis\OneDrive\Desktop\nah\Discord V14 bot\node_modules\discord.js\src\client\Client.js:479:12), <anonymous>:2:9)
at eval (eval at _eval (C:\Users\ddmis\OneDrive\Desktop\nah\Discord V14 bot\node_modules\discord.js\src\client\Client.js:479:12), <anonymous>:7:9)
at Client._eval (C:\Users\ddmis\OneDrive\Desktop\nah\Discord V14 bot\node_modules\discord.js\src\client\Client.js:479:12)
at ShardClientUtil._handleMessage (C:\Users\ddmis\OneDrive\Desktop\nah\Discord V14 bot\node_modules\discord.js\src\sharding\ShardClientUtil.js:194:82)
at process.emit (node:events:402:35)
at emit (node:internal/child_process:917:12)
at processTicksAndRejections (node:internal/process/task_queues:84:21)
node:internal/process/promises:246
triggerUncaughtException(err, true /* fromPromise */);
^

Error [ReferenceError]: newChannel is not defined
at eval (eval at _eval (C:\Users\ddmis\OneDrive\Desktop\nah\Discord V14 bot\node_modules\discord.js\src\client\Client.js:479:12), <anonymous>:2:9)
at eval (eval at _eval (C:\Users\ddmis\OneDrive\Desktop\nah\Discord V14 bot\node_modules\discord.js\src\client\Client.js:479:12), <anonymous>:7:9)
at Client._eval (C:\Users\ddmis\OneDrive\Desktop\nah\Discord V14 bot\node_modules\discord.js\src\client\Client.js:479:12)
at ShardClientUtil._handleMessage (C:\Users\ddmis\OneDrive\Desktop\nah\Discord V14 bot\node_modules\discord.js\src\sharding\ShardClientUtil.js:194:82)
at process.emit (node:events:402:35)
at emit (node:internal/child_process:917:12)
at processTicksAndRejections (node:internal/process/task_queues:84:21)
but it logs the guild name before crashing... also after the bot crashes it restarts itself automatically and thats weird cuz i dont have no such thing set up
40 Replies
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
wen
wenOP•2y ago
wen
wenOP•2y ago
but it happens only during that event and i have only one channelCreate listener do u need my shard.js file ? i dont understand sorry... how do i do a project wide search vs code ctrl + f ??
wen
wenOP•2y ago
@qjuh sorry i slept
wen
wenOP•2y ago
no
wen
wenOP•2y ago
well this is my event handler
wen
wenOP•2y ago
yes i save after every line 💀 ok so the error is not arising from the event file
wen
wenOP•2y ago
wen
wenOP•2y ago
that is the error it throws after logging the whole client object for some reason and then runs the bot again with the main file (index.js)
wen
wenOP•2y ago
it appears to be arising from here
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
wen
wenOP•2y ago
so i use the context object to pass in more properties that i need? like channelId or reply and stuff for example ? that actually makes total sense tysm!! oh btw... if i like define something outside the function... like let me = "bot" will it be accessible or do i need to { context: { text: me } } alright ty !!
wen
wenOP•2y ago
wen
wenOP•2y ago
it works if i do this... but I cant pass in the whole message object ?
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
wen
wenOP•2y ago
oh... so i need to import the class directly inside the function but like... i was able to pass message.author but not message
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
wen
wenOP•2y ago
so i'll have to fetch the message using the id inside the function fetch the channel*
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
wen
wenOP•2y ago
oh no reason... i'm sharding my bot before making it public... so i dont have problem if it's good... so im just learning and testing using shards to get used to it
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
wen
wenOP•2y ago
ouu got it so i can just use the usual code... but in any case suppose i need to fetch the channel using id... then i'll have to use broadcastEval right ??
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
wen
wenOP•2y ago
cuz im storing a log channel id in a database
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
wen
wenOP•2y ago
but how would i know if the guild belongs to that shard
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
wen
wenOP•2y ago
OH I SEE so i dont need to use broadcastEval in my cmds
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
wen
wenOP•2y ago
only in case i am not getting it by normal method then i'll use broadcastEval ?? right
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
wen
wenOP•2y ago
nothing sorry my bad... but if i want to do some stuff on another guild or channel
wen
wenOP•2y ago
wen
wenOP•2y ago
i'll do something like that right the second part
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
wen
wenOP•2y ago
alright tysm!
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
wen
wenOP•2y ago
if(!client.channels.cache.get(id)) {
//Use broadcast eval
}
if(!client.channels.cache.get(id)) {
//Use broadcast eval
}
like that ig
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
wen
wenOP•2y ago
alright tysm
Want results from more Discord servers?
Add your server