I need help with bot making on Discord.

Hey!! I’m new here. So I tried making a discord bot but its hard for a first timer. Everytime I do 

npm install discord.io winston -save

I always get a npm ERR

npm ERR! file C:\Users\HP\Desktop\DiscordBot\package.json
npm ERR! code EJSONPARSE
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected token b in JSON at position 101 while parsing near '...and fun.",
npm ERR! JSON.parse "main": bot.js",
npm ERR! JSON.parse "dependenc...'
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\HP\AppData\Roaming\npm-cache\_logs\2019-05-05T04_05_47_665Z-debug.log

Any suggestions? I also did try the holding shift then right click to open CMD< but it doesn’t work or I’m just blind. 

Hi and welcome @demonwolffang ,

It seems you are mixing up your  package.json and the actual code of your app.

Inside of a  package.json file there only should be  information about your app. The app code itself should reside in different files.

Are you comfortable sharing your code with us? You can publish it in a public GitHub repository if you want to - or, if it is a small project, put it in a GitHub Gist (https://gist.github.com/). That way we can better assist you.

1 Like

Hey thanks for the response!! Here;s the codings.

{
  "name": "demonsbot",
  "version": "1.0.0",
  "description": "A Bot used for Moderation",
  "main": "bot.js",
  "scripts": {
    "test": " "
  },
  "author": "Dylan",
  "license": "ISC"
}

That right now is the new coding since I re-did it and made the coding with cmd using the ‘nnpm init’ which I didn’t know since I’m still new to coding. 

And for the third notepad++ is this

var Discord = require('discord.io');
var logger = require('winston');
var auth = require('./auth.json');
// Configure logger settings
logger.remove(logger.transports.Console);
logger.add(new logger.transports.Console, {
    colorize: true
});
logger.level = 'debug';
// Initialize Discord Bot
var bot = new Discord.Client({
   token: auth.token,
   autorun: true
});
bot.on('ready', function (evt) {
    logger.info('Connected');
    logger.info('Logged in as: ');
    logger.info(bot.username + ' - (' + bot.id + ')');
});
bot.on('message', function (user, userID, channelID, message, evt) {
    // Our bot needs to know if it will execute a command
    // It will listen for messages that will start with `-`
    if (message.substring(0, 1) == '!') {
        var args = message.substring(1).split(' ');
        var cmd = args[0];

        args = args.splice(1);
        switch(cmd) {
            // !ping
            case 'ping':
                bot.sendMessage({
                    to: channelID,
                    message: 'Pong!'
                });
            break;
            // Just add any case commands if you want to..
         }
     }
});
1 Like

It seems you are following this tutorial: https://www.digitaltrends.com/gaming/how-to-make-a-discord-bot/

It does look pretty good. When exactly do you run into the error? When you do

npm install discord.io winston –save

or when you run

node bot.js

to actually run the bot?

To give a bit more backstory so you understand the situation better:

  • NPM is like a big collection of packages for the Node.js environment (which is basically JavaScript without a browser)
  • The  init command initializes the NPM locally in your directory, just like for example  git init would do
  • The  install xxx yyy -save  downloads the packages from NPM (in this case two), and puts them in your local directory so your application can use them
  • Using the  node command you run your bot

If you don’t understand it all I highly recommend reading this [https://medium.com/beginners-guide-to-mobile-web-development/introduction-to-npm-and-basic-npm-commands-18aa16f69f6b] - yes it’ll be a few minutes of your time but you’ll be able to better develop your bot after that.

Good luck, if you have any questions don’t hesitate to post back.

Yes I was using the digitaltrend one now I’m using a video with Visual Studio Code. Everything seems fine now but everytime I run 

node .

into the console it seems to be giving me this 

node : The term 'node' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ node .
+ ~~~~
    + CategoryInfo : ObjectNotFound: (node:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

While running that command. Although everything is in working order, no problems anywhere and this is the code I’m currently using.

Index.js 

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

const token = 'NTc0Mzg5NTY4NTY5MzQ0MDEx.XM4tgw.W8AnelJM9aw1eeR3j4K4dqa1kMg';

bot.on('ready', () =>{
    console.log ('This bot is online')
})

bot.login (token);

package.json

{
  "name": "demonsbot",
  "version": "1.0.0",
  "description": "A bot used for Server Moderation",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Dylan",
  "license": "ISC",
  "dependencies": {
    "discord.js": "^11.4.2"
  }
}

and the package-lock.json

{
  "name": "demonsbot",
  "version": "1.0.0",
  "lockfileVersion": 1,
  "requires": true,
  "dependencies": {
    "async-limiter": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz",
      "integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg=="
    },
    "discord.js": {
      "version": "11.4.2",
      "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-11.4.2.tgz",
      "integrity": "sha512-MDwpu0lMFTjqomijDl1Ed9miMQe6kB4ifKdP28QZllmLv/HVOJXhatRgjS8urp/wBlOfx+qAYSXcdI5cKGYsfg==",
      "requires": {
        "long": "^4.0.0",
        "prism-media": "^0.0.3",
        "snekfetch": "^3.6.4",
        "tweetnacl": "^1.0.0",
        "ws": "^4.0.0"
      }
    },
    "long": {
      "version": "4.0.0",
      "resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz",
      "integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA=="
    },
    "prism-media": {
      "version": "0.0.3",
      "resolved": "https://registry.npmjs.org/prism-media/-/prism-media-0.0.3.tgz",
      "integrity": "sha512-c9KkNifSMU/iXT8FFTaBwBMr+rdVcN+H/uNv1o+CuFeTThNZNTOrQ+RgXA1yL/DeLk098duAeRPP3QNPNbhxYQ=="
    },
    "safe-buffer": {
      "version": "5.1.2",
      "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
      "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
    },
    "snekfetch": {
      "version": "3.6.4",
      "resolved": "https://registry.npmjs.org/snekfetch/-/snekfetch-3.6.4.tgz",
      "integrity": "sha512-NjxjITIj04Ffqid5lqr7XdgwM7X61c/Dns073Ly170bPQHLm6jkmelye/eglS++1nfTWktpP6Y2bFXjdPlQqdw=="
    },
    "tweetnacl": {
      "version": "1.0.1",
      "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.1.tgz",
      "integrity": "sha512-kcoMoKTPYnoeS50tzoqjPY3Uv9axeuuFAZY9M/9zFnhoVvRfxz9K29IMPD7jGmt2c8SW7i3gT9WqDl2+nV7p4A=="
    },
    "ws": {
      "version": "4.1.0",
      "resolved": "https://registry.npmjs.org/ws/-/ws-4.1.0.tgz",
      "integrity": "sha512-ZGh/8kF9rrRNffkLFV4AzhvooEclrOH0xaugmqGsIfFgOE/pIz4fMc4Ef+5HSQqTEug2S9JZIWDR47duDSLfaA==",
      "requires": {
        "async-limiter": "~1.0.0",
        "safe-buffer": "~5.1.0"
      }
    }
  }
}

only getting the node . error when I try running it to get the bot online. 

Are you using Windows + PowerShell? If so, I think your PATH is not correctly configured for Node. First, make sure you’ve actually installed Node (which is the case, I think). Then refer to this answer: https://stackoverflow.com/a/52706872 to see if you can get the situation resolved.

Post back if you need more help.

I really didn’t understand this. Any better way to explain it? I got tothe change enviromental part but couldn’t figure out the rest sadly. 

Hmm. Are you on Windows? In that case, can you post the output of:

  1. Windows key + R
  2. Type  cmd
  3. Type  node -v

It should output a version number. If it doesn’t, we need to reconfigure your path.

If it does output a version number, change your directory to the directory your bot is in. You can do this using the  cd command. The run  node . .

Yes I’m on windows 10. I did the cmd node v and it displays version 12.1.0 

Oh and I don’t know how to change the files path sadly. 

First of all, I just noticed you probably publicly posted your Discord API token up above please make sure to request a new one from Discord.

Okay, so we now have established that your PATH is correcly set, Node is correctly installed and your developed app should work fine.

If you just forget the last part of my message, can you describe where exactly you’re stuck now? Still the same error as your initial post? 

The token was updated. But now everytime I try doing ‘node .’ within Visual Studio Code, the terminal just technically skips it and does nothing. With no response from the bot and still not going online. And I still don’t know what’s wrong with it at this point. 

et a npm ERR

npm ERR! file C:\Users\HP\Desktop\DiscordBot\package.json
npm ERR! code EJSONPARSE
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected token b in JSON at position 101 while parsing near '...and fun.",
npm ERR! JSON.parse "main": bot.js",
npm ERR! JSON.parse "dependenc...'
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\HP\AppData\Roaming\npm-cache\_logs\2019-05-05T04_05_47_665Z-debug.log

Any suggestions? I also did try the holding shift then right click to open CMD< but it doesn’t work or I’m just blind. 

@demonwolffang wrote:

Hey!! I’m new here. So I tried making a discord bot but its hard for a first timer. Everytime I do 

npm install discord.io winston -save

I always get a npm ERR

npm ERR! file C:\Users\HP\Desktop\DiscordBot\package.json
npm ERR! code EJSONPARSE
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected token b in JSON at position 101 while parsing near ‘…and fun.",
npm ERR! JSON.parse “main”: bot.js",
npm ERR! JSON.parse "dependenc…’
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\HP\AppData\Roaming\npm-cache_logs\2019-05-05T04_05_47_665Z-debug.log

Any suggestions? I also did try the holding shift then right click to open CMD< but it doesn’t work or I’m just blind. 

 

 

Ok and I said everything was updated using Visual Studio Code and not Notepad++. In Visual Studio Code I’m having no erros, but the bot just doesn’t want to start everytime I do ‘node .’ and just does absolutely nothing but go to a new command. Couldn’t it be a line error or a wrong command I’m doing? 

@demonwolffang what if you try running  node bot.js  (or  node app.js  if your file is called  app.js  instead of  bot.js )? Do you get the inital error back, or does it run? If you do, check this thread out to see if you can get it resolved: https://stackoverflow.com/questions/24920142/package-json-must-be-actual-json-not-just-javascript

@ceckin6 That looks pretty similar! Have you tried some of the solutions in this topic already? You could also check out the link I posted above for @demonwolffang . Finally, it might be helpful to post your  package.json (using a GitHub Gist (https://gist.github.com/) for example).

Its just the issue where  I run 

node .

But it does nothing. 

Where exactly did you pick up the idea to use  node . ? Because I don’t think that is the command you actually want to use. You are more likely to want to start your application. Thus, you need to provide the name of the file your application consists of. In your case that should be  app.jsbot.js , or similar. At least something ending in  .js.

What  node .  does, is just give the current directory you’re in ( . means “current directory” in the shell) to the node interpeter. It’s not something Node can handle.

So just try to run your  bot.js or  app.js file directly using  node bot.js  (or  node app.js ).

Sorry for the late response, was dealing with school and still am. In the video I watched (https://www.youtube.com/watch?v=X_qg0Ut9nU8)

Said to use the ‘node .’ 

Hi @demonwolffang ,

I suspect that the person in the video uses  node .  because his main code file is called  index.js. So you could either:

  • Also name your code file  index.js  instead of bot.js / app.js ;
  • or run it using  node bot.js node app.js

The file was automatically named index.js and still is. I tried running ‘node .’ in CMD and the node.js app, but continue getting the same response 

node .
...