Feel like I'm missing something obvious.. how do I find out the correct signature for a
run
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?
import { Events, Listener, ListenerOptions } from "@sapphire/framework";import { logger } from "@repo/logger";export class GuildCreateListener extends Listener { public constructor(context: Listener.LoaderContext, options?: ListenerOptions) { super(context, { ...options, event: Events.GuildCreate, once: true, }); } public run(): void { //?? const guildName = "???"; //?? logger.info(`The bot has been added to a new server! ${guildName}`, "Bot Added"); }}
import { Events, Listener, ListenerOptions } from "@sapphire/framework";import { logger } from "@repo/logger";export class GuildCreateListener extends Listener { public constructor(context: Listener.LoaderContext, options?: ListenerOptions) { super(context, { ...options, event: Events.GuildCreate, once: true, }); } public run(): void { //?? const guildName = "???"; //?? logger.info(`The bot has been added to a new server! ${guildName}`, "Bot Added"); }}
Solution
The only thing you can do is
extends Listener<typeof Events.GuildCreate>
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.