Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

236
Visualizações
Running into an error with getting music bot to join VC
const ytdl = require('ytdl-core');
const ytSearch = require('yt-search');

module.exports = {
name: 'play',
description: "plays music in voice chat",
async execute(message, args, Discord){
    const voiceChannel = message.member.voice.channel;
  
    if (!voiceChannel) return message.channel.send('You need to be in a voice channel to listen to music!');
    const permissions = voiceChannel.permissionsFor(message.client.user);
    if (!permissions.has('CONNECT')) return message.reply("You don't have the correct permissions to request music!");
    if (!permissions.has('SPEAK')) return message.reply("You don't have the correct permissions to request music!");
    if (!args.length) return message.channel.send("You Can't Request for no Music Silly >_<");

  const connection = await voiceChannel.join();

  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(`:Thumbsup: Now Playing >>>${video.title}<<<`)
    } else {
      message.reply('No Video Results Found :(');
    }
  }
}

My Error message is const connection = await voiceChannel.join();

TypeError: voiceChannel.join is not a function

If any of you have a suggestion that may work please feel free to edit it. It can also only detect if someone is in voice chat at start up of the bot, so if your in voice chat at start of bot it sends the in voice chat message while your in and out of voice chat

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

While transitioning from discord.js v12 - v13 we have encountered a breaking change that is switching to @discordjs/voice a seperate library for voice to play with discord.js, now as suggested from the comment here I see you're using the most latest version of discord.js where the VoiceChannel#join method no longer exists. You have to propose the following changes:

  • Install @discordjs/voice using npm install @discordjs/voice
  • You need to establish a voiceConnection, and further create an AudioPlayer instance and go ahead and call the AudioPlayer#subscribe method to this player, you would have to do some base additions for the same which are exhibited below:
const {
    joinVoiceChannel,
    createAudioPlayer,
    createAudioResource
} = require('@discordjs/voice');

const connection = joinVoiceChannel({
    channelId: message.member.voice.channel.id,
    guildId: message.guild.id,
    adapterCreator: message.guild.voiceAdapterCreator,
});

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

const player = createAudioPlayer();
const resource = createAudioResource(stream);

async function play() {
    await player.play(resource);
    connection.subscribe(player);
}

They just made it overcomplex for beginners to comprehend so don't worry! If you feel like you're over- exhausting yourselves you can always downgrade to a lower version like so:

npm uninstall discord.js
npm install discord.js@12.5.3

Welcome to stackoverflow 😄

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda