cobalt
cobalt
Explore posts from servers
DIAdiscord.js - Imagine an app
Created by cobalt on 10/3/2022 in #djs-voice
Won't play any audio
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"}}
ready
subscribed
playing
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"}}
ready
subscribed
playing
the bot joins the vc, but nothing happens after that
12 replies