Problem with play cmd

if (msg.content.toLowerCase().startsWith(';play')) {
const voiceChannel = msg.member.voice.channel;

if (!voiceChannel) {
return msg.reply('be in vc');
}

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

const songUrl = args[1];

if (!songUrl) {
return msg.reply('giv me the link of the song');
}

play(connection, songUrl);
}
if (msg.content.toLowerCase().startsWith(';play')) {
const voiceChannel = msg.member.voice.channel;

if (!voiceChannel) {
return msg.reply('be in vc');
}

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

const songUrl = args[1];

if (!songUrl) {
return msg.reply('giv me the link of the song');
}

play(connection, songUrl);
}
first is the cmd, next one is function play:
function play(connection, songUrl) {
const stream = ytdl(songUrl, { filter: 'audioonly' });
const resource = createAudioResource(stream, { inputType: StreamType.Arbitrary });

audioPlayer.play(resource);
connection.subscribe(audioPlayer);

audioPlayer.on('stateChange', (oldState, newState) => {
if (newState.status === 'idle') {
connection.destroy();
}
});
}
function play(connection, songUrl) {
const stream = ytdl(songUrl, { filter: 'audioonly' });
const resource = createAudioResource(stream, { inputType: StreamType.Arbitrary });

audioPlayer.play(resource);
connection.subscribe(audioPlayer);

audioPlayer.on('stateChange', (oldState, newState) => {
if (newState.status === 'idle') {
connection.destroy();
}
});
}
when i join in the voice then i type ;play linkfothesong, bot join but he doesnt play the music also there is no error in console
10 Replies
d.js toolkit
d.js toolkit6mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
treble/luna
treble/luna6mo ago
we do not support TOS violations
Neca
Neca6mo ago
what u mean with tos violations?
treble/luna
treble/luna6mo ago
ytdl is against TOS
Neca
Neca6mo ago
oh i didnt know that i will try with discord player
treble/luna
treble/luna6mo ago
anything using youtube is against TOS
Neca
Neca6mo ago
then what i can use for the songs?
treble/luna
treble/luna6mo ago
something TOS compliant
Neca
Neca6mo ago
aham, can i use mp3 files? like to link in code where is mp3 file and then bot to play it i can put free content i just want to play like some long comfor music while im working some things with friends
d.js docs
d.js docs6mo ago
guide Getting Started: Introduction - Debugging Dependencies read more