Millenium is here
Millenium is here
DIAdiscord.js - Imagine an app
Created by Millenium is here on 1/16/2024 in #djs-voice
Error: Cannot play a resource that has already ended.
Hey, i have thsi error when im trying to play a radio flux url like (for example) http://belrtl.ice.infomaniak.ch/belrtl-mp3-192.mp3 This is my code:
const { joinVoiceChannel, createAudioPlayer, createAudioResource, StreamType, entersState } = require("@discordjs/voice");

const voice = require('@discordjs/voice');

module.exports = async (channel, track) => {


try {
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guildId,
adapterCreator: channel.guild.voiceAdapterCreator,
});

const player = createAudioPlayer();

const resource = createAudioResource(track, { inlineVolume: true });
resource.volume.setVolume(0.1 * vol);

connection.on(voice.VoiceConnectionStatus.Ready, () => {
player.play(resource);
});

connection.on(voice.VoiceConnectionStatus.Disconnected, async (oldState, newState) => {
try {
await Promise.race([
entersState(connection, voice.VoiceConnectionStatus.Signalling, 5_000),
entersState(connection, voice.VoiceConnectionStatus.Connecting, 5_000),
]);
} catch (error) {
console.error(error)
} finally {
player.stop();
connection.destroy()
}
});


player.on('error', error => {
console.error(error);
player.stop();
connection.destroy();
});

connection.subscribe(player);
} catch (error) {
console.error(error);
}
};
const { joinVoiceChannel, createAudioPlayer, createAudioResource, StreamType, entersState } = require("@discordjs/voice");

const voice = require('@discordjs/voice');

module.exports = async (channel, track) => {


try {
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guildId,
adapterCreator: channel.guild.voiceAdapterCreator,
});

const player = createAudioPlayer();

const resource = createAudioResource(track, { inlineVolume: true });
resource.volume.setVolume(0.1 * vol);

connection.on(voice.VoiceConnectionStatus.Ready, () => {
player.play(resource);
});

connection.on(voice.VoiceConnectionStatus.Disconnected, async (oldState, newState) => {
try {
await Promise.race([
entersState(connection, voice.VoiceConnectionStatus.Signalling, 5_000),
entersState(connection, voice.VoiceConnectionStatus.Connecting, 5_000),
]);
} catch (error) {
console.error(error)
} finally {
player.stop();
connection.destroy()
}
});


player.on('error', error => {
console.error(error);
player.stop();
connection.destroy();
});

connection.subscribe(player);
} catch (error) {
console.error(error);
}
};
46 replies
DIAdiscord.js - Imagine an app
Created by Millenium is here on 10/29/2022 in #djs-voice
My bot take a lot of seconds to start playing the music
HII
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
selfDeaf: true,
});
const resource = createAudioResource(radio, {
inputType: StreamType.WebmOpus,
inlineVolume: true
});
resource.volume.setVolume(0.1 * (vol));
const player = createAudioPlayer();
player.play(resource);
connection.subscribe(player);
player.on('error', error => {
console.error('Error:', error.message);
});
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
selfDeaf: true,
});
const resource = createAudioResource(radio, {
inputType: StreamType.WebmOpus,
inlineVolume: true
});
resource.volume.setVolume(0.1 * (vol));
const player = createAudioPlayer();
player.play(resource);
connection.subscribe(player);
player.on('error', error => {
console.error('Error:', error.message);
});
Is there anything to optimise? ? My bot take a lot of seconds to start playing the music
3 replies