JavaScript bot won't start

Question:


Repl link:

code snippet

I Need help because my repl won’t work at all. PLS help me.

const { Client, Intents } = require('discord.js');
const Distube = require('distube');

// Crea un nuovo client con gli intents richiesti
const client = new Client({
  // Gli intents richiesti dipendono dalle funzionalità del tuo bot
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.MESSAGES,
    Intents.FLAGS.MESSAGE_CONTENTS,
    Intents.FLAGS.MESSAGE_CREATE,
    Intents.FLAGS.VOICE_STATES,
    // Aggiungi altri intents necessari a seconda delle tue esigenze
  ],
});

// Crea un'istanza di Distube
const distube = new Distube(client);

// Evento ready che viene chiamato quando il bot si connette con successo
client.once('ready', () => {
  console.log(`Bot è online come ${client.user.tag}`);
});

// Evento message che viene chiamato quando un messaggio viene inviato nel server
client.on('message', async (message) => {
  // Controlla se il messaggio è stato inviato da un bot o se non inizia con il prefisso
  if (message.author.bot || !message.content.startsWith('!')) return;

  // Effettua il parsing del comando e degli argomenti
  const args = message.content.slice(1).trim().split(/ +/);
  const command = args.shift().toLowerCase();

  // Gestisci il comando !play
  if (command === 'play') {
    // Controlla se l'utente si trova in un canale vocale
    if (!message.member.voice.channel) {
      return message.channel.send('Devi essere in un canale vocale per poter usare questo comando!');
    }

    // Verifica se il bot è già connesso a un canale vocale
    if (!message.guild.me.voice.connection) {
      // Connetti il bot al canale vocale dell'utente
      await message.member.voice.channel.join();
    }

    // Ottieni la query di ricerca
    const query = args.join(' ');

    // Esegui la ricerca della canzone con Distube
    await distube.play(message, query);
  }
});

// Gestisci gli eventi di Distube
distube
  .on('playSong', (message, queue, song) => {
    message.channel.send(`Sto riproducendo ora: **${song.name}**`);
  })
  .on('addSong', (message, queue, song) => {
    message.channel.send(`Ho aggiunto: **${song.name}** alla coda di riproduzione`);
  })
  .on('error', (message, error) => {
    console.error(error);
    message.channel.send('Si è verificato un errore durante la riproduzione della musica');
  });

// Effettua l'accesso al tuo bot Discord utilizzando il tuo token
client.login('TOKEN_DEL_BOT');

Hey, @Phone-Hacks-Try welcome to the forums!

Can you please provide a link to the repl? This way it is easier for staff and members of the community to help you!

Also see this guide on how to share your code:

2 Likes