简体   繁体   English

语法错误:意外的令牌,不和谐的机器人编码

[英]Syntax Error: Unexpected Token, discord bot coding

I am not great at coding, really i'm still learning, but usually I can solve my own problems, however, i'm stuck here.我不擅长编码,实际上我仍在学习,但通常我可以解决自己的问题,但是,我被困在这里。 I 'm not sure what is preventing the bot from running, Here is my current code:我不确定是什么阻止了机器人运行,这是我当前的代码:

 const Discord = require("discord.js");

const TOKEN = "myToken";
const PREFIX = "f!"
var bot = new Discord.Client();

bot.on("ready", function() {
    console.log("Ready");
});
bot.on("message", function (message) {
    if (message.author.equals(bot.user)) return;

    if (!message.content.startsWith(PREFIX)) return;

    var args = message.content.substring(PREFIX.length).split(" ");

    switch (args[0]) {
        case "ping";
            message.channel.sendMessage("Pong!");
            break;
    }

});

bot.login(TOKEN);

However, when i run it in cmd with the command "node index", it doesn't run, even though the previous version I made did work, when i try to run this version, I get the following error statements;但是,当我使用命令“节点索引”在 cmd 中运行它时,它不会运行,即使我制作的先前版本确实有效,当我尝试运行此版本时,我收到以下错误语句;

SyntaxError: Unexpected token )
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:588:28)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Function.Module.runMain (module.js:665:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:607:3

Any help would be appreciated, sorry if i sound like a total idiot.任何帮助将不胜感激,对不起,如果我听起来像个白痴。

The problem is in switch statement, you need : after case , but there is ;问题出在switch语句中,您需要:case之后,但是有;

switch (args[0]) {
        case "ping"; //here should be :
            message.channel.sendMessage("Pong!");
            break;
}

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

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