I have a problem where I've joined a voice channel and I want to play a song but the bot tells me to join a voice channel even though I'm already in one here's an image
Here's my code:
import ytdl from 'ytdl-core'
import ytSearch from 'yt-search'
export const name = 'play';
export const description = 'Play a desired song!';
export const args = 1;
export const usage = '{song}';
export const execute = async (message, args) => {
const voiceChannel = message.member.voice.channel;
if (!voiceChannel) return message.channel.send('Please join a voice channel first!');
const connection = await joinVoiceChannel();
const videoFinder = async (query) => {
const videoResult = await ytSearch(query);
return (videoResult.videos.length > 1) ? videoResult.videos[0] : null;
}
const video = await videoFinder(args.join(' '));
if (video) {
const stream = ytdl(video.url, { filter: 'audioonly' });
connection.play(stream, { seek: 0, volume: 1 })
.on('finish', () => {
voiceChannel.leave();
});
await message.reply(`:arrow_forward: Now playing ***${video.title}***`)
} else {
message.channel.send(`I could not find the video :c`)
}
}
This is the first time I'm asking for help here, so if something isn't clear please ask me any questions!
Help would be heavily appreciated (I think it's because joinVoiceChannel(); is not a function.)