Listener run() signature
Feel like I'm missing something obvious.. how do I find out the correct signature for a
run
method of any given listener - they're different for each event.
I'm sure there's an obvious way to get this, without trial and error and debugging to see what's available to it - where am I not looking?
Solution:Jump to solution
The only thing you can do is
extends Listener<typeof Events.GuildCreate>
but that won't implicitly type the run parameters, it'll just error if you provide the wrong types. Sadly TS offers nothing better.7 Replies
For this example, I can of course refer to the discord docs - but I would have expected this information should be available somehow in the framework itself, or aided in some way by TS - am I missing something?
Discord.js
Discord.js is a powerful node.js module that allows you to interact with the Discord API very easily. It takes a much more object-oriented approach than most other JS Discord libraries, making your bot's code significantly tidier and easier to comprehend.
Solution
The only thing you can do is
extends Listener<typeof Events.GuildCreate>
but that won't implicitly type the run parameters, it'll just error if you provide the wrong types. Sadly TS offers nothing better.could they be annotated in the Events const? would maybe provide the benefit of
event: Events.GuildCreate
providing a intelisense hint of Accepts a single Guild parameter
etc
Though I imagine this may change over time and fall out of date.Yeah.... It's the outdated part that's kind of annoying. I suppose it's still something though.
Maybe we can make a script that auto updates them
Maybe there's some way to infer the link to the discord doc based on the event name? And it would become a
Refer to <link> for usage information
etc
script would be ideal approach. I'm unsure if this is a common problem/question though
I'll mark as solved, thanks for the context 👍Tsdoc cannot use dynamic content. A script would still have to inject it into the TS code. Feasible though with some trickery.