Bot not outputting sound after joining the channel

const play = async (song, connection, message) => {
if (!song) {
connection.leave();
return;
}
console.log('music start')
connection.play(createAudioResource(song.url))
// .on("finish", () => {
// message.client.music_queue.shift();
// play(message.client.music_queue[0], connection, message);
// })

}
const play = async (song, connection, message) => {
if (!song) {
connection.leave();
return;
}
console.log('music start')
connection.play(createAudioResource(song.url))
// .on("finish", () => {
// message.client.music_queue.shift();
// play(message.client.music_queue[0], connection, message);
// })

}
The code seem to be called but not giving any output. I suspect there is an issue in the player to connection connection?
try {
const connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: guildId,
adapterCreator: message.guild.voiceAdapterCreator
})

const player = createAudioPlayer();
connection.subscribe(player);

playSong(musicQueue[0], player, message);

} catch(err) {
console.log(err)
}
try {
const connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: guildId,
adapterCreator: message.guild.voiceAdapterCreator
})

const player = createAudioPlayer();
connection.subscribe(player);

playSong(musicQueue[0], player, message);

} catch(err) {
console.log(err)
}
above is the connection code
12 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
wjael
wjaelOP2y ago
I use v14.11.0 with 18.5 node version
wjael
wjaelOP2y ago
wjael
wjaelOP2y ago
seems like the audio pauses after started playing?
amlsx
amlsx2y ago
the issue is with the player to connection connection. The connection.play() method expects a MediaStream object, but the createAudioResource() method returns a URL object. To fix this, you can use the createMediaStream() method to create a MediaStream object from the URL object.
LuckyBuda10
LuckyBuda102y ago
how can you use the createMediaStream() function i am having a similar issue
wjael
wjaelOP2y ago
I'll test it out ty! can I ask you where the createMediaStream is from?
LuckyBuda10
LuckyBuda102y ago
im trynna find that out too @ me if you ever find it
wjael
wjaelOP2y ago
sure you too 🙂
LuckyBuda10
LuckyBuda102y ago
yo @! o _ o ! try running this command npm install @discordjs/voice libsodium-wrappers turns out I didn't have this library installed. and installing it made everything work
let connection = getVoiceConnection(message.guild);
if (connection === undefined) {
connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator,
selfDeaf: false,
selfMute: false
});
}

let player = createAudioPlayer();
connection.subscribe(player);

const findVid = async (query) => {
const vidRes = await ytSearch(query);
return (vidRes.videos.length > 1) ? vidRes.videos[0] : null;
}
const video = await findVid(msgList.join(''));

if (video) {
const stream = ytdl(video.url, {
filter: "audioonly"
});
var resource = createAudioResource(stream);

player.play(resource);

starterEmbed.setTitle(`Now Playing: ${video.title}`);
starterEmbed.setImage(video.thumbnail);
starterEmbed.setFooter(`Requested by: ${message.author.}`);
} else {
return message.channel.send("Eror finding video");
}
let connection = getVoiceConnection(message.guild);
if (connection === undefined) {
connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator,
selfDeaf: false,
selfMute: false
});
}

let player = createAudioPlayer();
connection.subscribe(player);

const findVid = async (query) => {
const vidRes = await ytSearch(query);
return (vidRes.videos.length > 1) ? vidRes.videos[0] : null;
}
const video = await findVid(msgList.join(''));

if (video) {
const stream = ytdl(video.url, {
filter: "audioonly"
});
var resource = createAudioResource(stream);

player.play(resource);

starterEmbed.setTitle(`Now Playing: ${video.title}`);
starterEmbed.setImage(video.thumbnail);
starterEmbed.setFooter(`Requested by: ${message.author.}`);
} else {
return message.channel.send("Eror finding video");
}
thats my code if you're interested
wjael
wjaelOP2y ago
Thank you for helping. @luckybuda10 It works! Thank you very much!
LuckyBuda10
LuckyBuda102y ago
yea no problem I was so relived when i found that
Want results from more Discord servers?
Add your server