简体   繁体   English

我的 discord 机器人出现“SyntaxError: Unexpected end of input”

[英]I'm getting a “SyntaxError: Unexpected end of input” on my discord bot

ive tried multiple sites with answers and so far none of them have worked.我尝试了多个带有答案的站点,但到目前为止,它们都没有奏效。 here is the code:这是代码:

    // Run dotenv
    require('dotenv').config();
    // Import libraries
    const Discord = require('discord.js');
    const client = new Discord.Client();

    // Event listener when a user connectd to the server
    client.on('ready', () => {
        console.log(`Logged in as ${client.user.tag}!`);
    });

    // Event listener when a user sends a message in the chat
    client.on('message', msg => {
    
    // We check the message content and look for the word "ping", so we can have the bot respong "pong"
    client.on('message', msg => {
      if (msg.content === 'ping') {
        msg.channel.send('pong');
    
           }; 

    });

    client.login(process.env.DISCORD_TOKEN); 

this is the error I'm getting:这是我得到的错误:

    C:\Users\creep\discord-greeter-bot\bot.js:24
    client.login(process.env.DISCORD_TOKEN)


    SyntaxError: Unexpected end of input
    [90m    at wrapSafe (internal/modules/cjs/loader.js:1047:16)[39m
    [90m    at Module._compile (internal/modules/cjs/loader.js:1097:27)[39m
    [90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)[39m
    [90m    at Module.load (internal/modules/cjs/loader.js:977:32)[39m
    [90m    at Function.Module._load (internal/modules/cjs/loader.js:877:14)[39m
    [90m    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)[39m
    [90m    at internal/main/run_main_module.js:18:47[39m

so according to this code, my error is on the last line.所以根据这段代码,我的错误在最后一行。 I'm not sure how else to edit it because I've tried rearranging the brackets, adding more, changing the code entirely, and rewriting it from scratch.我不确定如何编辑它,因为我尝试重新排列括号,添加更多,完全更改代码,并从头开始重写。 I don't understand which part of my code is incorrect and I've been struggling for a few days any help would be greatly appreciated我不明白我的代码的哪一部分不正确,我已经苦苦挣扎了几天,任何帮助将不胜感激

Edit: it was working before then i added all the "//" messages and it just stopped.编辑:在此之前它正在工作,然后我添加了所有“//”消息,它就停止了。 im not sure why but i dont think they would have an effect.我不知道为什么,但我认为它们不会有效果。 i also changed the token but i did replace the one in the.env file with the new one.我也更改了令牌,但我确实用新的替换了 .env 文件中的那个。

You have client.on('message', msg => { twice in your code, and you only close it once, so at the end of the file, you have an open ({ , so it should work if you remove one of them.您的代码中有client.on('message', msg => {两次,并且您只关闭它一次,因此在文件末尾,您有一个 open ({ ,因此如果您删除其中一个,它应该可以工作他们。

As for the comments with // affecting it, those comments are literally removed from the code before compiling it, and will have no effect on how the code runs.至于带有//影响它的注释,这些注释在编译之前从字面上从代码中删除,并且不会影响代码的运行方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM