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);
}
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();
}
});
}
16 replies