1
votes

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;

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.

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 recommend 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.)Kaynn

1 Answers

1
votes

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;
}