new Socket
src/gateway.ts:141new Socket(token: string, options?: SocketOptions)A connection to Discord's gateway. Handles identifying, heartbeats, resuming and compression, and emits every dispatch as a raw packet.
import { Gateway } from 'detritus-client-socket';
Gateway.Socket;new Socket(token: string, options?: SocketOptions)callConnect(channelId: string, callback?: Function): voidcleanup(code?: string | number, reason?: string): voidconnect(url?: string | URL | null): voiddecode(data: any, uncompressed?: boolean): anydisconnect(code?: number, reason?: string): voidemitPackets(): voidEmits the queued raw packets in order, one immediate for every packet handled in the same tick
getIdentifyData(): IdentifyDatagetResumeData(): ResumeDataguildStreamCreate(
guildId: string,
options: { channelId: string; preferredRegion?: string },
callback?: Function,
): voidhandle(data: any, uncompressed?: boolean): voidhandleDispatch(name: string, data: any): voidheartbeat(fromInterval?: boolean, requested?: boolean): voididentify(): voididentifyTry(): Promise<void>kill(error?: Error): voidlobbyConnect(lobbyId: string, lobbySecret: string, callback?: Function): voidlobbyDisconnect(lobbyId: string, callback?: Function): voidlobbyVoiceStatesUpdate(
voiceStates: { lobbyId: string; selfDeaf: boolean; selfMute: boolean }[],
callback?: Function,
): voidmakePresence(options?: PresenceOptions): RawPresenceon(event: string | symbol, listener: (...args: any[]) => void): thisAdds the listener function to the end of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.
server.on('connection', (stream) => {
console.log('someone connected!');
});Returns a reference to the EventEmitter, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// aThe callback function
on(
event: CLOSE | "close",
listener: (payload: { code: number; reason: string }) => any,
): thison(event: KILLED | "killed", listener: (payload: { error?: Error }) => any): thison(event: OPEN | "open", listener: (target: BaseSocket) => any): thison(event: PACKET | "packet", listener: (packet: Packet) => any): thison(event: READY | "ready", listener: () => any): thison(event: SOCKET | "socket", listener: (socket: BaseSocket) => any): thison(
event: STATE | "state",
listener: (__namedParameters: { state: SocketStates }) => any,
): thison(event: WARN | "warn", listener: (error: Error) => any): thisonClose(target: BaseSocket, code?: number, reason?: string): voidonError(target: BaseSocket, error: Error): voidonIdentifyCheck(): boolean | Promise<boolean>onMessage(target: BaseSocket, data: any, isBinary?: boolean): voidonOpen(target: BaseSocket): voidping(timeout?: number): Promise<any>requestApplicationCommands(
guildId: string,
options: { applicationId?: string; applications: boolean; limit?: number; nonce: string; offset?: number; query?: string },
): voidrequestChannelInfo(guildId: string, fields?: string[], callback?: Function): voidrequestGuildMembers(
guildIds: string | string[],
options: { limit: number; nonce?: string; presences?: boolean; query?: string; userIds?: string[] },
callback?: Function,
): voidrequestSoundboardSounds(guildIds: string | string[], callback?: Function): voidresume(): voidsend(op: number, d: any, callback?: Function, priority?: boolean): voidsetHeartbeat(data: Hello): voidsetPresence(options?: PresenceOptions, callback?: Function): voidsetState(value: SocketStates): voidstreamDelete(streamKey: string, callback?: Function): voidstreamPing(streamKey: string, callback?: Function): voidstreamSetPaused(streamKey: string, paused: boolean, callback?: Function): voidstreamWatch(streamKey: string, callback?: Function): voidsyncGuild(guildIds: string[], callback?: Function): voidupdateGuildSubscriptions(
guildId: string,
options?: { activities?: boolean; channels?: { [channelId: string]: […, …][] }; members?: string[]; typing?: boolean },
callback?: Function,
): voidvoiceConnect(
guildId?: string | null,
channelId?: string | null,
options?: { forceMode?: string; receive?: boolean; selfDeaf?: boolean; selfMute?: boolean; selfVideo?: boolean; timeout?: number; video?: boolean },
): Promise<Socket | null>voiceServerPing(callback?: Function): voidvoiceStateUpdate(
guildId?: string | null,
channelId?: string | null,
options?: { preferredRegion?: string; selfDeaf?: boolean; selfMute?: boolean; selfVideo?: boolean },
callback?: Function,
): void