Library
Are you a developer of the discord api library? Wow, I'm your fan too :0. Or you simply want the library you are using to support rainlink? Well, you can refer to this article.
Understanding how library implementation works
The way the Library class works is quite similar to Shoukaku. So you can absolutely copy from Shoukaku to use in rainlink
Example:
import { AbstractLibrary } from 'rainlink';
import { RainlinkNodeOptions } from 'rainlink';
export class OceanicJS extends AbstractLibrary {
// sendPacket is where your library send packets to Discord Gateway
public sendPacket(shardId: number, payload: any, important: boolean): void {
return this.client.shards.get(shardId)?.send(payload.op, payload.d, important);
}
// getId is a getter where the lib stores the client user (the one logged in as a bot) id
public getId(): string {
return this.client.user.id;
}
// Listen attaches the event listener to the library you are using
public listen(nodes: RainlinkNodeOptions[]): void {
// Only attach to ready event once, refer to your library for its ready event
this.client.once('ready', () => this.ready(nodes));
// Attach to the raw websocket event, this event must be 1:1 on spec with dapi (most libs implement this)
this.client.on('packet', (packet: any) => this.raw(packet));
}
}
Table of Contents