admin管理员组

文章数量:1390503

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 mand "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;

SyntaxError: Unexpected token )
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._pile (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.

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 mand "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;

SyntaxError: Unexpected token )
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._pile (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.

Share Improve this question edited Apr 2, 2018 at 18:42 André 4,4974 gold badges33 silver badges58 bronze badges asked Oct 1, 2017 at 19:36 Marley S.Marley S. 191 gold badge1 silver badge2 bronze badges 1
  • By the way, do not post your token publicly to anyone. Always keep tokens to yourself. This is because anyone can access to your bot as long as they have the token. (I remend you reset your bot's token now) In the future, just replace the values of the token to something else that isn't a token. (People will get it as long as the value/variable name is not misleading.) – WQYeo Commented Oct 1, 2017 at 19:51
Add a ment  | 

1 Answer 1

Reset to default 1

The problem is in switch statement, you need : after case, but there is ;

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

本文标签: javascriptSyntax Error Unexpected Tokendiscord bot codingStack Overflow