#Basic js question

27 messages · Page 1 of 1 (latest)

twilit zealot
const sharder = new Client(options)
sharder.spawn()

module.exports = sharder

So if i wanna import it to my eval cmd file i can directly do it like const sharder = require("shard.js")
And then use it's properties like sharder.ipc.send

unkempt hatchBOT
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
meager stream

yes, have you tried it yet?

twilit zealot

I'm coding after a long time so lacking basics

I'm gonna try it sir

urban nimbus

No

twilit zealot
urban nimbus

no

twilit zealot

Umm then sir ?

What's the correct way to do it

urban nimbus

when you create sharder object you should pass by value through functions to where you need the properties in other files

const sharder = new Client(...)
// later , when you are reading command files maybe
command.execute(interaction, sharder)

// in file of command
execute(interaction, sharder) {
  // can use sharder here
}
twilit zealot
urban nimbus

you said you have eval command what do you mean you are not loading any commands

twilit zealot

My sharder starts my cluster, client and then deploys cmds but in a seperate file but i only wanna use it in eval cmd so...

urban nimbus

Ok there is another way

use client.shard.broadcastEval

twilit zealot

So any way to export my sharder then import it somewhere else

urban nimbus

ok

ignore what i said before

you can do what you posted in the first message

but do not reassign anything, it is static and will end up being cached because you are exporting it

it is just bad practice if you are not using something like a singleton

and even then it is discouraged with exporting client for example

wintry cloak

if that's your sharder wouldn't it run in a completely different process than your eval command?