Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 3
Message 1 of 42

I need help with bot making on Discord.

Solved! Go to Solution.

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. 

 

 

41 Replies
Commander Lvl 3
Message 2 of 42

Re: I need help with bot making on Discord.

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.


- Mark
Copilot Lvl 3
Message 3 of 42

Re: I need help with bot making on Discord.

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..
         }
     }
});
Highlighted
Commander Lvl 3
Message 4 of 42

Re: I need help with bot making on Discord.

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-comma...] - 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.


- Mark
Copilot Lvl 3
Message 5 of 42

Re: I need help with bot making on Discord.

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. 

Commander Lvl 3
Message 6 of 42

Re: I need help with bot making on Discord.

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.


- Mark
Copilot Lvl 3
Message 7 of 42

Re: I need help with bot making on Discord.

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. 

Commander Lvl 3
Message 8 of 42

Re: I need help with bot making on Discord.

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 . .


- Mark
Copilot Lvl 3
Message 9 of 42

Re: I need help with bot making on Discord.

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

Copilot Lvl 3
Message 10 of 42

Re: I need help with bot making on Discord.

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