Every time I give in There’s a mistake

Asked

Viewed 133 times

-3

I am programming a BOT for Discord and I cannot resolve the error below:

> SyntaxError: Unexpected end of input
>     at wrapSafe (internal/modules/cjs/loader.js:1072:16)
>     at Module._compile (internal/modules/cjs/loader.js:1122:27)
>     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)        
>     at Module.load (internal/modules/cjs/loader.js:1002:32)
>     at Function.Module._load (internal/modules/cjs/loader.js:901:14)
>     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
>     at internal/main/run_main_module.js:18:47

My code :

const Discord = require('discord.js')
const bot = new Discord.Client(); 
const ytdl = require('ytdl-core')
const streamOptions = {seek: 0, volume: 1};

const token = 'Njg4NTc1NzE1NzE3MDIxNzUx.Xm2UKA.stJB8VEHvjpfOVsR6qw1NGOceLs';
bot.login(token);

bot.on('ready', () => {
    console.log('estou pronto para ser usado');
});

bot.on('message', msg => {}
    if(msg.author.bot) {
          return;   
    }

    if(msg.content.indexOf("youtube")!==-1 && msg.content.toLowerCase(),startsWith ("?play"))
        let CompleteMessage = msg.content.split('');

        let youtubeLink = CompleteMessage [1];

        if (VoiceChannel == null) {
            console.log('Canal nâo foi encontrado!');
        }

        if (VoiceChannel !== null) {
            console.log('O canal foi encontrado!');

            VoiceChannel.join()
            .then(connection => {
                const stream = ytdl(youtubeLink, {filter:'audioonly'});

                const DJ = connection.playStream(stream, streamOptions)
                DJ.on('end', end => {
                    VoiceChannel.leave();

                });
            })
            .catch(console.error);
        }
  • This happens when you just type node or when you try to run your code with Node ? If this is the case, you should put your code for us to analyze.

  • Missing a piece at the end of the source, a key and a parenthesis, to close bot.on('message', ... if it is missing in real code, will give syntax error even.

  • Vlw more... when I went to type Node gave the following message : Lexical declaration cannot appear in a single-statement context

1 answer

1

I believe it is some syntax error. in the following line:

bot.on('message', msg => {}

if and everything else has to stay inside the keys

example:

const Discord = require('discord.js');
const client = new Discord.Client();

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

client.on('message', msg => {
  if (msg.content === 'ping') {
    msg.reply('Pong!');
  }
});

Reference: https://discord.js.org/#/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.