Bot doesn't play one song

49 Views Asked by At

hi if i play thi song https://www.youtube.com/watch?v=fupL7GLEuCE the bot block and doesn't respond at my command, the bot enter in voice channel but doesn't play the music and if a play another song the bot doesn't respond at the new commmand, only thing i can do is restart the bot with node .

How can i solve this problem

this is my code:

const discord = require('discord.js');
const { EmbedBuilder } = require('discord.js');
const { SpotifyPlugin } = require("@distube/spotify")
const { SoundCloudPlugin } = require("@distube/soundcloud")
const { YtDlpPlugin } = require("@distube/yt-dlp");
const { DisTube } = require('distube');
const { ActionRowBuilder, ButtonBuilder, ButtonStyle} = require('discord.js');





const client = new discord.Client({
  intents: [
    discord.GatewayIntentBits.Guilds,
    discord.GatewayIntentBits.GuildMessages,
    discord.GatewayIntentBits.GuildVoiceStates,
    discord.GatewayIntentBits.MessageContent
  ]
});

const distube = new DisTube(client, {
  leaveOnStop: false,
  leaveOnEmpty: true,
  emitNewSongOnly: true,
  emitAddSongWhenCreatingQueue: false,
  emitAddListWhenCreatingQueue: false,
  plugins: [new SpotifyPlugin(), new SoundCloudPlugin(), new YtDlpPlugin()]
});

client.once('ready', () => {
  console.log(`Logged in as ${client.user.tag}`);
  client.user.setActivity('   -   ');
});

const config = {
  prefix: '-',
  token: 'TOKEN',
};

client.on("messageCreate", async (message) => {
  if (message.author.bot || !message.inGuild()) return;
  
  if (message.mentions.has(client.user)){
    
    const embed = new EmbedBuilder()
    .setDescription('Che cazzo vuoi coglione di merda il mio prefisso è `-`')
    return message.channel.send({ embeds: [embed] });
  }
  
  if (!message.content.startsWith(config.prefix)) return;
  const args = message.content
    .slice(config.prefix.length)
    .trim()
    .split(/ +/g);
  const command = args.shift();
  if (command === 'play' || command === 'p') {
  
    
    const voiceChannel = message.member.voice.channel;
    if (!voiceChannel) return message.channel.send('Devi essere in un canale vocale per utilizzare questo comando.');

    const songQuery = args.join(' ');
    if (!songQuery) return message.channel.send('Devi specificare una canzone o un URL valido.');
    
  

    try {
      await distube.play(message.member.voice.channel, songQuery, {
        member: message.member,
        textChannel: message.channel,
        message: message
      });
    } catch (error) {
      console.error(error);
      message.channel.send('❌ Si è verificato un errore durante la riproduzione');
    } 
  } 

  else if (command === 'skip' || command === 's') {
  const queue = distube.getQueue(message);
  if (!queue) return message.channel.send(' La coda è vuota');
  if (queue.songs.length <= 1){
  message.channel.send(' Non c\'è nulla in coda per saltare');
  }
  else{
    try{
      await distube.skip(message);
    message.channel.send('⏭ Saltata la canzone attuale');
    } catch(error){
    console.error(error);}
  }
  }

else if (command === 'stop') {
  const queue = distube.getQueue(message);
  if (!queue) return message.channel.send(' La coda è vuota');
  try{
    await distube.stop(message);
    message.channel.send(' La canzone è stata interrotta');
    } catch(error){
    console.error(error);}
  
}

else if (command === 'restart') {
  const queue = distube.getQueue(message);
  if (!queue) return message.channel.send(' La coda è vuota');
  try{
    await distube.seek(message, 0);
    message.channel.send(' La canzone è ricominciata');
    } catch(error){
    console.error(error);}
  
}


else if (command === 'resume'|| command === 'r') {
  const queue = distube.getQueue(message);
  if (!queue) return message.channel.send(' La coda è vuota');
  try{await
  distube.resume(message);
  message.channel.send('▶️ La canzone è stata ripresa');
  } catch(error){
  console.error(error);}
  
}


else if (command === 'pause') {
  const queue = distube.getQueue(message);
  if (!queue) return message.channel.send('La coda è vuota');
  try{await
  distube.pause(message);
  message.channel.send('⏸️ La canzone è stata messa in pausa');
  } catch(error){
  console.error(error);}
}

  else if (command === 'sparacino') {
  const button= new ActionRowBuilder()
  .addComponents(
    new ButtonBuilder()
    .setCustomId('button')
    .setLabel('CLICCAMI')
    .setStyle(ButtonStyle.Success)
  )

  const embed = new EmbedBuilder()
    .setTitle('SPARACINO È UNA ')
    .setDescription('SE VUOI VEDERLO CLICCA IL PULSANTE')
    .setImage('https://i.imgur.com/frb7mz8.jpg')    
  
  const embed2 = new EmbedBuilder()
      .setTitle('ECCOLO QUI')
      .setImage('https://i.imgur.com/lGQFqLm.png');
  
      message.channel.send({ embeds: [embed], components: [button] });
      const collector = message.channel.createMessageComponentCollector({
        max: '1', 
        time: '60000', 

    });

      collector.on('collect',async i =>{
        try {await i.update({ embeds: [embed2], components: []})}
        catch(error){
          console.error(error);}

      })
  }




else if (command === 'ping'){
  const embed = new EmbedBuilder()
  .setDescription('Pong')
  .setColor('#0099ff')    
  message.channel.send({ embeds: [embed] });
}

else if (command === 'racism'){
  const embed = new EmbedBuilder()
  .setImage('https://cdn.discordapp.com/attachments/972954024905175061/1084606665510359140/received_547985302928296_1.gif')
    
  message.channel.send({ embeds: [embed] });
}

else if (command === 'help') {
  const embed = new EmbedBuilder()
  .addFields({name:'DJ commands', value : '`play`,`pause`,`resume`,`stop`,`loop`,`skip`,`sparacino`,`restart`,`ping`'  })
  .setColor('#0099ff')    
  message.channel.send({ embeds: [embed] });
}

if (['repeat', 'loop'].includes(command)) {
  const queue = distube.getQueue(message);
  if (!queue) return message.channel.send('La coda è vuota');

  try{
  const mode = distube.setRepeatMode(message);
  await
  message.channel.send(
    `Set repeat mode to \`${
      mode
        ? mode === 2
          ? 'All Queue'
          : 'This Song'
        : 'Off'
    }\``,
  );
  } catch(error){
    console.error(error);}
}

});



distube.on("playSong", (queue, song) => {
  
  const embed = new EmbedBuilder()
    .setTitle(' Riproducendo')
    .addFields({name:'Canzone', value : song.name  })
    .addFields({name:'Durata', value : song.formattedDuration  })
    .setColor('#0099ff')
    .setThumbnail(song.thumbnail)
    queue.textChannel.send({ embeds: [embed] });
  
});


distube.on('addSong', (queue, song) => {
  const embed = new EmbedBuilder()
  .setTitle('Aggiunta canzone')
  .addFields({name:'Canzone', value : song.name  })
  .setColor('#0099ff')
  .setThumbnail(song.thumbnail)
  queue.textChannel.send({ embeds: [embed] }); 
  
});

client.login(config.token);
0

There are 0 best solutions below