Last active
May 22, 2021 01:35
-
-
Save jpbberry/3b48029bb5dd596ce2e1c3d8c43093e1 to your computer and use it in GitHub Desktop.
Voice adapter for discord-rose in TypeScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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