{"_id":"57858bff9e80c32200234f52","parentDoc":null,"user":"57858823fc4a0f2200f02f01","project":"57858bff9e80c32200234f4c","version":{"_id":"57858bff9e80c32200234f4f","__v":3,"project":"57858bff9e80c32200234f4c","createdAt":"2016-07-13T00:31:59.708Z","releaseDate":"2016-07-13T00:31:59.708Z","categories":["57858bff9e80c32200234f50","57858e1b8a711d2000d1252b","5785a2bf2eca4e0e002b4d67"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"Stable. I Hope.","version_clean":"0.3.0","version":"0.3.00"},"__v":3,"category":{"_id":"57858bff9e80c32200234f50","__v":0,"version":"57858bff9e80c32200234f4f","project":"57858bff9e80c32200234f4c","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-07-13T00:31:59.735Z","from_sync":false,"order":0,"slug":"documentation","title":"Documentation"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-07-13T00:31:59.773Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"This tutorial will get on started on making a bot using all the available features of the Disnode Library. This will get updated as more features get added!\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"NEED HELP?\",\n  \"body\": \"We understand the Disnode's documentation is lacking and we working hard in expanding it. If you need help or have and questions please feel free to join our discord server: [![Discord](https://discordapp.com/api/servers/149771756176015360/widget.png?style=button)](https://discord.gg/0prrdN1joHCrVhdw)\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"1. Installing and Getting Bot Token\"\n}\n[/block]\n# Installing\n\n`npm install disnode --save`\nThat simple! Note you will most likely have to compile many of the C Files used by 3rd party packages. Heres a great tutorial on how to set this up, but if its already setup on your machine, it should just build automatically.\n\n# Getting API Keys\n## Discord\n1. Go to: [https://discordapp.com/](https://discordapp.com/) and create an account/login (Normal Discord user account is fine)\n2. Then Navigate to More->Developers->MyApplications or go to https://discordapp.com/developers/applications/me\n3. Click new application and fill out the info for your bot. (REDIRECT NOT NECESSARY FOR BOTS)\n4. Then click Create Bot User.\n5. Congrats you created your bot. Now bookmark this page as its info will be useful later on.\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"2. Initilzting Disnode\"\n}\n[/block]\n# Base Bot Code\nNow you have the required packages and API Keys. Lets begin the code! We're going section by section here, but full source code will provided.\n\nFirst things first lets require disnode at the top of our code.  \n`var Disnode = require(\"disnode\")`\n\nThen we are going to create our bot using the Disnode constructor. We pass in our Discord Bot User Token and a path to our config. Now keep this private and out of your git commits (trust me).   \n`var mybot = new Disnode(\"DISCORD_BOTUSER_TOKEN\" ,\"PATH/TO/CONFIG.json\")`\n\nNow we are going to create an empty object for storing custom commands we write inside this bot class. More in this coming in a later tutorial.\n`var myCommands = {}`\n\nNow we have the base of our code and can start the bot by calling  \n`mybot.startBot();`   \nNothing will happen. Sorry to get you hyped but we havn't assigned it to do anything. So shall we make it do something?\n\nCURRENT CODE:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var Disnode = require(\\\"disnode\\\");\\nvar myBot = new Disnode(\\\"KEY\\\",\\\"./BotConfig.json\\\");\\nvar myCommands = {};\\n\\n//...\\n\\nmyBot.startBot();\",\n      \"language\": \"javascript\",\n      \"name\": \"MyBot.js\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"3. Events\"\n}\n[/block]\nFirst things lets set our events. Currently Disnode sends out these events:\n`\n* `Bot_Init` Called when we start our bot.     \n* `Bot_Ready` Called when the bot has successfully logged into Discord. (usually takes 1-2s)       \n* `Bot_RawMessage` Called when Any Message is sent in any channel or server. Good for logging but for running commands we       have our own system you might enjoy ;)\n\nSince these are impliment like normal events in NodeJS well just copy the boilerplate into our bot.\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var Disnode = require(\\\"disnode\\\");\\nvar myBot = new Disnode(\\\"KEY\\\",\\\"./BotConfig.json\\\");\\nvar myCommands = {};\\n\\n\\nmyBot.on(\\\"Bot_Init\\\", function () { \\n  console.log(\\\"[MyBot] Bot Init.\\\");\\n});\\n\\nmyBot.on(\\\"Bot_Ready\\\", function () { \\n  console.log(\\\"[MyBot] Bot Ready.\\\");\\n});\\n\\nmyBot.on(\\\"Bot_RawMessage\\\", function (msg) { \\n  console.log(\\\"[MyBot] RawMessage: \\\" + msg.author.name + \\\" :: \\\" + msg.content);;\\n});\\n\\nmyBot.startBot();\",\n      \"language\": \"javascript\",\n      \"name\": \"MyBot.js\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"4. Loading Config\"\n}\n[/block]\nOur bot config is where our commands and manager settings are loaded from, so its important to load it first. We do this by calling the `loadConfig(cb)` function in Disnode. loadConfig takes in a callback which is called after the config has been successfully loaded.\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"IMPORTANT\",\n  \"body\": \"Load your managers after you config has been loaded, else you will get null errors!\"\n}\n[/block]\nWe can implement it as such to out bot. \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var Disnode = require(\\\"disnode\\\");\\nvar myBot = new Disnode(\\\"KEY\\\",\\\"./BotConfig.json\\\");\\nvar myCommands = {};\\n\\n\\nmyBot.on(\\\"Bot_Init\\\", function () { \\n  console.log(\\\"[MyBot] Bot Init.\\\");\\n});\\n\\nmyBot.on(\\\"Bot_Ready\\\", function () { \\n  console.log(\\\"[MyBot] Bot Ready.\\\");\\n  \\n  myBot.loadConfig(OnLoad);\\n  \\n});\\n\\nmyBot.on(\\\"Bot_RawMessage\\\", function (msg) { \\n  console.log(\\\"[MyBot] RawMessage: \\\" + msg.author.name + \\\" :: \\\" + msg.content);;\\n});\\n\\nvar OnLoad = function(){\\n}\\n\\nmyBot.startBot();\",\n      \"language\": \"javascript\",\n      \"name\": \"MyBot.js\"\n    }\n  ]\n}\n[/block]\nNow also create a `BotConfig.json` file in your root directory of your bot. (NOTE: This file can be named anything and put anywhere, just make sure its the same as the path you specified in your bot's constructor).\n\nInside this file just type: `{commands: []}` and save it. This is just an empty JSON object that will be filled when the bot starts up! Later we plan to make this automated.\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"5. Loading Managers!\"\n}\n[/block]\nNow to the fun part! Loading managers. For this example well just be loading Core Managers, but we have information on how to load third-party manager here: [Managers Explaintion](https://disnode.readme.io/docs/managers). \n\nFor this bot, we want to have these features (manager name):\n  *  Read Commands (CommandHandler)\n  * Play Audio (MusicManager)\n  * Help Command (HelpManager)\n  * Add Commands from Chat (SayManager)\n\nTo load a manager, you call `addManager({name,options}` from Disnode. The name parameter is the name of the Manager (Should be the same as the Filename) and options are is an object of options that the manager takes in. This should be specified in the managers documentation.\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"MANAGER NAMING\",\n  \"body\": \"Managers all always be named the same throughout, including configs, filenames, variables, etc.\"\n}\n[/block]\nNow our bot with managers added:\n\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var Disnode = require(\\\"disnode\\\");\\nvar myBot = new Disnode(\\\"KEY\\\",\\\"./BotConfig.json\\\");\\nvar myCommands = {};\\n\\n\\nmyBot.on(\\\"Bot_Init\\\", function () { \\n  console.log(\\\"[MyBot] Bot Init.\\\");\\n});\\n\\nmyBot.on(\\\"Bot_Ready\\\", function () { \\n  console.log(\\\"[MyBot] Bot Ready.\\\");\\n  \\n  myBot.loadConfig(OnLoad);\\n  \\n});\\n\\nmyBot.on(\\\"Bot_RawMessage\\\", function (msg) { \\n  console.log(\\\"[MyBot] RawMessage: \\\" + msg.author.name + \\\" :: \\\" + msg.content);;\\n});\\n\\nvar OnLoad = function(){\\n  myBot.addManager({name:\\\"CommandHandler\\\", options:{prefix: \\\"!\\\"}});\\n  myBot.addManager({name: \\\"VoiceManager\\\", options:{voiceEvents:true}});\\n  myBot.addManager({name:\\\"MusicManager\\\", options:{maxVolume:2.0}});\\n  myBot.addManager({name:\\\"HelpManager\\\", options:{}});\\n\\tmyBot.addManager({name:\\\"SayManager\\\", options:{}});\\n  \\n  myBot.CommandHandler.LoadList(myBot.config.commands); // Load Commands from Config\\n\\n}\\n\\nmyBot.startBot();\",\n      \"language\": \"javascript\",\n      \"name\": \"MyBot.js\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"6. PROFIT!\"\n}\n[/block]\nThats it! You should have a functional bot now! If you go to your bots config file after starting it up, you should see all the default values and commands. Typing \"!help\" should list all commands and their usage. Now in the next steps, well going to be writing custom commands in our bot.","excerpt":"This page will help you get started with Disnode. You'll be up and running in a jiffy!","slug":"getting-started","type":"basic","title":"Getting Started with Disnode"}

Getting Started with Disnode

This page will help you get started with Disnode. You'll be up and running in a jiffy!

This tutorial will get on started on making a bot using all the available features of the Disnode Library. This will get updated as more features get added! [block:callout] { "type": "info", "title": "NEED HELP?", "body": "We understand the Disnode's documentation is lacking and we working hard in expanding it. If you need help or have and questions please feel free to join our discord server: [![Discord](https://discordapp.com/api/servers/149771756176015360/widget.png?style=button)](https://discord.gg/0prrdN1joHCrVhdw)" } [/block] [block:api-header] { "type": "basic", "title": "1. Installing and Getting Bot Token" } [/block] # Installing `npm install disnode --save` That simple! Note you will most likely have to compile many of the C Files used by 3rd party packages. Heres a great tutorial on how to set this up, but if its already setup on your machine, it should just build automatically. # Getting API Keys ## Discord 1. Go to: [https://discordapp.com/](https://discordapp.com/) and create an account/login (Normal Discord user account is fine) 2. Then Navigate to More->Developers->MyApplications or go to https://discordapp.com/developers/applications/me 3. Click new application and fill out the info for your bot. (REDIRECT NOT NECESSARY FOR BOTS) 4. Then click Create Bot User. 5. Congrats you created your bot. Now bookmark this page as its info will be useful later on. [block:api-header] { "type": "basic", "title": "2. Initilzting Disnode" } [/block] # Base Bot Code Now you have the required packages and API Keys. Lets begin the code! We're going section by section here, but full source code will provided. First things first lets require disnode at the top of our code. `var Disnode = require("disnode")` Then we are going to create our bot using the Disnode constructor. We pass in our Discord Bot User Token and a path to our config. Now keep this private and out of your git commits (trust me). `var mybot = new Disnode("DISCORD_BOTUSER_TOKEN" ,"PATH/TO/CONFIG.json")` Now we are going to create an empty object for storing custom commands we write inside this bot class. More in this coming in a later tutorial. `var myCommands = {}` Now we have the base of our code and can start the bot by calling `mybot.startBot();` Nothing will happen. Sorry to get you hyped but we havn't assigned it to do anything. So shall we make it do something? CURRENT CODE: [block:code] { "codes": [ { "code": "var Disnode = require(\"disnode\");\nvar myBot = new Disnode(\"KEY\",\"./BotConfig.json\");\nvar myCommands = {};\n\n//...\n\nmyBot.startBot();", "language": "javascript", "name": "MyBot.js" } ] } [/block] [block:api-header] { "type": "basic", "title": "3. Events" } [/block] First things lets set our events. Currently Disnode sends out these events: ` * `Bot_Init` Called when we start our bot. * `Bot_Ready` Called when the bot has successfully logged into Discord. (usually takes 1-2s) * `Bot_RawMessage` Called when Any Message is sent in any channel or server. Good for logging but for running commands we have our own system you might enjoy ;) Since these are impliment like normal events in NodeJS well just copy the boilerplate into our bot. [block:code] { "codes": [ { "code": "var Disnode = require(\"disnode\");\nvar myBot = new Disnode(\"KEY\",\"./BotConfig.json\");\nvar myCommands = {};\n\n\nmyBot.on(\"Bot_Init\", function () { \n console.log(\"[MyBot] Bot Init.\");\n});\n\nmyBot.on(\"Bot_Ready\", function () { \n console.log(\"[MyBot] Bot Ready.\");\n});\n\nmyBot.on(\"Bot_RawMessage\", function (msg) { \n console.log(\"[MyBot] RawMessage: \" + msg.author.name + \" :: \" + msg.content);;\n});\n\nmyBot.startBot();", "language": "javascript", "name": "MyBot.js" } ] } [/block] [block:api-header] { "type": "basic", "title": "4. Loading Config" } [/block] Our bot config is where our commands and manager settings are loaded from, so its important to load it first. We do this by calling the `loadConfig(cb)` function in Disnode. loadConfig takes in a callback which is called after the config has been successfully loaded. [block:callout] { "type": "warning", "title": "IMPORTANT", "body": "Load your managers after you config has been loaded, else you will get null errors!" } [/block] We can implement it as such to out bot. [block:code] { "codes": [ { "code": "var Disnode = require(\"disnode\");\nvar myBot = new Disnode(\"KEY\",\"./BotConfig.json\");\nvar myCommands = {};\n\n\nmyBot.on(\"Bot_Init\", function () { \n console.log(\"[MyBot] Bot Init.\");\n});\n\nmyBot.on(\"Bot_Ready\", function () { \n console.log(\"[MyBot] Bot Ready.\");\n \n myBot.loadConfig(OnLoad);\n \n});\n\nmyBot.on(\"Bot_RawMessage\", function (msg) { \n console.log(\"[MyBot] RawMessage: \" + msg.author.name + \" :: \" + msg.content);;\n});\n\nvar OnLoad = function(){\n}\n\nmyBot.startBot();", "language": "javascript", "name": "MyBot.js" } ] } [/block] Now also create a `BotConfig.json` file in your root directory of your bot. (NOTE: This file can be named anything and put anywhere, just make sure its the same as the path you specified in your bot's constructor). Inside this file just type: `{commands: []}` and save it. This is just an empty JSON object that will be filled when the bot starts up! Later we plan to make this automated. [block:api-header] { "type": "basic", "title": "5. Loading Managers!" } [/block] Now to the fun part! Loading managers. For this example well just be loading Core Managers, but we have information on how to load third-party manager here: [Managers Explaintion](https://disnode.readme.io/docs/managers). For this bot, we want to have these features (manager name): * Read Commands (CommandHandler) * Play Audio (MusicManager) * Help Command (HelpManager) * Add Commands from Chat (SayManager) To load a manager, you call `addManager({name,options}` from Disnode. The name parameter is the name of the Manager (Should be the same as the Filename) and options are is an object of options that the manager takes in. This should be specified in the managers documentation. [block:callout] { "type": "info", "title": "MANAGER NAMING", "body": "Managers all always be named the same throughout, including configs, filenames, variables, etc." } [/block] Now our bot with managers added: [block:code] { "codes": [ { "code": "var Disnode = require(\"disnode\");\nvar myBot = new Disnode(\"KEY\",\"./BotConfig.json\");\nvar myCommands = {};\n\n\nmyBot.on(\"Bot_Init\", function () { \n console.log(\"[MyBot] Bot Init.\");\n});\n\nmyBot.on(\"Bot_Ready\", function () { \n console.log(\"[MyBot] Bot Ready.\");\n \n myBot.loadConfig(OnLoad);\n \n});\n\nmyBot.on(\"Bot_RawMessage\", function (msg) { \n console.log(\"[MyBot] RawMessage: \" + msg.author.name + \" :: \" + msg.content);;\n});\n\nvar OnLoad = function(){\n myBot.addManager({name:\"CommandHandler\", options:{prefix: \"!\"}});\n myBot.addManager({name: \"VoiceManager\", options:{voiceEvents:true}});\n myBot.addManager({name:\"MusicManager\", options:{maxVolume:2.0}});\n myBot.addManager({name:\"HelpManager\", options:{}});\n\tmyBot.addManager({name:\"SayManager\", options:{}});\n \n myBot.CommandHandler.LoadList(myBot.config.commands); // Load Commands from Config\n\n}\n\nmyBot.startBot();", "language": "javascript", "name": "MyBot.js" } ] } [/block] [block:api-header] { "type": "basic", "title": "6. PROFIT!" } [/block] Thats it! You should have a functional bot now! If you go to your bots config file after starting it up, you should see all the default values and commands. Typing "!help" should list all commands and their usage. Now in the next steps, well going to be writing custom commands in our bot.