#Anybody an idea how you can create custom Event Files which automatically load the correct callback

1 messages · Page 1 of 1 (latest)

umbral mist
#

Use modules

red rivet
#

you mean importing the client and then just call client.on(....)

umbral mist
#

Something like

export let name = "interactionCreate";
export let run = ...
red rivet
#

Thats no problem hahaah

umbral mist
#

You could import the client indeed, so you don't need to pass it at every run

red rivet
#

But i want the correct type to be loaded
Overall your solution is really bad, a lot of problems can be caused through that kind of implementation

umbral mist
#

The correct type will still be loaded for client

red rivet
#

You have to define run somehow, else its just guessing or always looking in the docs

#

then its even better to just export the client and call client.on("event",()=>{})

umbral mist
#

If you're talking about parameters for run, then you're right

red rivet
#

thats what i am saying giving the correct callback

umbral mist
#
export default () => {client.on(...)}```
red rivet
#

You can do it like that but its just not a good implementation
Managing events as own objects and loading them to client seems to be the best implementation (especially when you have multiple bots in a project)

red rivet
umbral mist
#

Explain..

red rivet
#

Having an event object which i can just load as an object to my Client

eventfiles.map(e=>{
client.on(e.event,e.run)
}```
umbral mist
#

You want to map to event loader?

#

I don't see what you're trying to achieve in the end.. Reloading events?

red rivet
#

pretty much
Having the events as their own object
something like

type ClientEvent = {
event : ClientEvents,
run :  ?!
}


#

must e.run not e,run

umbral mist
#

You get typing for run only when used in a client.on() context, or if you specify it. Since you don't want to specify it, where you have run, you must have client.on()

#

It's hard to find a compromise, because you're not using events like they were supposed to