const connection = joinVoiceChannel({ channelId: channel.id, guildId: channel.guild.id, adapterCreator: channel.guild.voiceAdapterCreator, selfDeaf: false,});const player = createAudioPlayer({ behaviors: { noSubscriber: NoSubscriberBehavior.Pause },}).on("error", (error) => { connection.disconnect(); throw error;});console.log("inited");connection .on(VoiceConnectionStatus.Ready, () => { console.log("ready"); connection.subscribe(player); console.log("subscribed"); player.play( createAudioResource( createReadStream( path.resolve( path.dirname(url.fileURLToPath(import.meta.url)), "filePath.ogg", ), ), { inputType: StreamType.OggOpus }, ), ); console.log("playing"); // player.on(AudioPlayerStatus.Idle, connection.disconnect); }) .on(VoiceConnectionStatus.Disconnected, async () => { console.log("disconnect?"); try { await Promise.race([ entersState(connection, VoiceConnectionStatus.Signalling, 5_000), entersState(connection, VoiceConnectionStatus.Connecting, 5_000), ]); // Seems to be reconnecting to a new channel - ignore disconnect } catch { console.log("disconnect"); // Seems to be a real disconnect which SHOULDN'T be recovered from connection.destroy(); player.stop(); } }) .on("error", (error) => { connection.disconnect(); throw error; });
const connection = joinVoiceChannel({ channelId: channel.id, guildId: channel.guild.id, adapterCreator: channel.guild.voiceAdapterCreator, selfDeaf: false,});const player = createAudioPlayer({ behaviors: { noSubscriber: NoSubscriberBehavior.Pause },}).on("error", (error) => { connection.disconnect(); throw error;});console.log("inited");connection .on(VoiceConnectionStatus.Ready, () => { console.log("ready"); connection.subscribe(player); console.log("subscribed"); player.play( createAudioResource( createReadStream( path.resolve( path.dirname(url.fileURLToPath(import.meta.url)), "filePath.ogg", ), ), { inputType: StreamType.OggOpus }, ), ); console.log("playing"); // player.on(AudioPlayerStatus.Idle, connection.disconnect); }) .on(VoiceConnectionStatus.Disconnected, async () => { console.log("disconnect?"); try { await Promise.race([ entersState(connection, VoiceConnectionStatus.Signalling, 5_000), entersState(connection, VoiceConnectionStatus.Connecting, 5_000), ]); // Seems to be reconnecting to a new channel - ignore disconnect } catch { console.log("disconnect"); // Seems to be a real disconnect which SHOULDN'T be recovered from connection.destroy(); player.stop(); } }) .on("error", (error) => { connection.disconnect(); throw error; });
Console output:
inited[VOICE] received voice state update: {/*...*/}[VOICE] received voice server: {"t":"VOICE_SERVER_UPDATE","s":7,"op":0,"d":{"token":"removed","guild_id":"removed","endpoint":"us-central5335.discord.media:443"}}readysubscribedplaying
inited[VOICE] received voice state update: {/*...*/}[VOICE] received voice server: {"t":"VOICE_SERVER_UPDATE","s":7,"op":0,"d":{"token":"removed","guild_id":"removed","endpoint":"us-central5335.discord.media:443"}}readysubscribedplaying
the bot joins the vc, but nothing happens after that
Recent Announcements
Continue the conversation
Join the Discord to ask follow-up questions and connect with the community
d-Iaa
discord.js - Imagine an app
Support server for discord.js, a Node.js module to interact with Discord's apps API.