Skip to content

Instantly share code, notes, and snippets.

@jpbberry
Last active May 22, 2021 01:35
Show Gist options
  • Save jpbberry/3b48029bb5dd596ce2e1c3d8c43093e1 to your computer and use it in GitHub Desktop.
Save jpbberry/3b48029bb5dd596ce2e1c3d8c43093e1 to your computer and use it in GitHub Desktop.
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