Skip to content

Instantly share code, notes, and snippets.

@jpbberry
Last active May 22, 2021
Embed
What would you like to do?
Voice adapter for discord-rose in TypeScript
import { GatewayVoiceServerUpdateDispatchData, GatewayVoiceState } from "discord-api-types";
const connection = Voice.joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild_id,
adapterCreator: (methods) => {
const voiceServerUpdate = (data: GatewayVoiceServerUpdateDispatchData) => {
methods.onVoiceServerUpdate(data)
}
const voiceStateUpdate = (data: GatewayVoiceState) => {
methods.onVoiceStateUpdate(data)
}
this.worker.on('VOICE_SERVER_UPDATE', voiceServerUpdate)
this.worker.on('VOICE_STATE_UPDATE', voiceStateUpdate)
Voice.entersState(player, Voice.AudioPlayerStatus.Idle, 30e3)
.then(() => {
connection.destroy()
})
return {
sendPayload: (data) => {
// @ts-expect-error ws is a private property
return this.worker.guildShard(channel.guild_id).ws._send(data)
},
destroy: () => {
this.worker.off('VOICE_SERVER_UPDATE', voiceServerUpdate)
this.worker.off('VOICE_STATE_UPDATE', voiceStateUpdate)
}
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment