Neca
Neca
DIAdiscord.js - Imagine an app
Created by Neca on 12/31/2023 in #djs-voice
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
16 replies