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

141
Visualizações
sigue reproduciendo la canción incluso si alguien más se unió al canal

Hola, estoy tratando de hacer que el bot reproduzca canciones específicas, luego quiero que el bot abandone el canal y lo logré, pero el problema es que cuando alguien más se une al canal mientras el bot está reproduciendo, reinicia la reproducción de las canciones.

 client.on('voiceStateUpdate', async (oldState, newState) => { const channel = client.channels.cache.get('921118985876017217') if (oldState.channel == null && newState.channel == channel) { await new Promise(function (resolve , reject) { resolve( joinVoiceChannel({ channelId: channel.id, guildId: newState.guild.id, adapterCreator: newState.guild.voiceAdapterCreator })) let stream = ytdl('https://www.youtube.com/watch?v=TU1i6I1ms6s', { filter: "audioonly", fmt: "mp3", encoderArgs: ['-af', 'bass=g=10'], }) let secStream = ytdl('https://www.youtube.com/watch?v=wHqKkiHlvJc&list=RDwHqKkiHlvJc&start_radio=1', { filter: "audioonly", fmt: "mp3", encoderArgs: ['-af', 'bass=g=10'], }) const resource = createAudioResource(stream, { inputType: StreamType.Arbitrary, inlineVolume: true, }); // resource.volume.setVolume(0.5); const secReasorce = createAudioResource(secStream, { inputType: StreamType.Arbitrary, /* StreamType.Arbitrary type of the song like mpe */ inlineVolume: true, }); const player = createAudioPlayer(); player.play(resource) const connection = getVoiceConnection(oldState.guild.id) connection.subscribe(player) player.on(AudioPlayerStatus.Idle, () =>setTimeout(() => { try{ {player.play(secReasorce)} }catch{ connection.destroy() } }, 3000)) player.on( AudioPlayerStatus.Playing , ()=>{ //I think there will be the solution but I don't know any functions does what I want } ) })

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

0

Debe realizar un seguimiento de si ya está reproduciendo audio o no. Dado que está obteniendo el canal basado en una identificación; Supongo que solo lo estás usando en un canal de voz. Entonces, podría tener un booleano fuera del alcance de la expresión lambda que realiza un seguimiento de si se está reproduciendo.

Si implementas eso, tendrías algo como esto:

 let isPlaying = false; // Create a variable to keep track of whether it's playing or not. client.on('voiceStateUpdate', async (oldState, newState) => { // If it's already playing, return and do nothing. if (isPlaying) return; const channel = client.channels.cache.get('921118985876017217') if (oldState.channel == null && newState.channel == channel) { await new Promise(function (resolve , reject) { resolve( joinVoiceChannel({ channelId: channel.id, guildId: newState.guild.id, adapterCreator: newState.guild.voiceAdapterCreator })) isPlaying = true; // Bot successfully joined vc, it now begins to play audio. // Removed code unrelated to the answer so you can more easily see the changes. player.on(AudioPlayerStatus.Idle, () =>setTimeout(() => { try{ {player.play(secReasorce)} }catch{ // I assume this is where you make it disconnect? // If so, retain the integrity of `isPlaying` by setting it back to false. isPlaying = false; connection.destroy() } }, 3000)) })```
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