Let's Learn How to Create a Steemit Discord Bot Tutorial
technology·@kinganima·
0.000 HBDLet's Learn How to Create a Steemit Discord Bot Tutorial
Today I will try to share a bit of information with you on how to build your very own steemit discord app. Ever since I joined this awesome platform a few weeks ago I have been intrigued by it. One thing that really interested me was all of the bots on this platform.  As a result, I have been researching to find the best solutions to build my own. So today I will share with you those results. Just to note, a lot of this information came from other authors here on steemit and elsewhere on the web. I will just be paraphrasing. You can view other awesome guides like this one [here](https://steemit.com/technology/@codingdefined/let-s-learn-how-to-create-a-discord-bot). For this tutorial, we will learn how to create a discord bot using Node.js. If you are not familiar with node.js please watch this video for a quick overview. <iframe width="854" height="480" src="https://www.youtube.com/embed/pU9Q6oiQNd0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe> Additioally, Node.js uses v8 javascript engine which is the same engine used by Chrome browser. It is event driven and has non-blocking standard libraries which means if you are doing any I/O bound operations, it will happen asynchronously. Node.js is not a framework neither it is a programming language, it is just a run time environment for developing server-side web applications. You can use Node.js for creating I/O bound applications, data streaming applications, single page applications etc, but it is not advisable to use Node.js for CPU intensive applications. When we are discussing Node.js Basics then you should be familiar about NPM. NPM is a node package manager which handles and resolves dependencies. It makes easy for JavaScript developers to share and re-use code and it makes it easy to update the code that you're sharing. It is been called as an online repository for Node.js packages/modules. To install modules using npm you need to run below command npm install package_name. Node.js is very easy to install. Installers can be downloaded from Node.js Download Page. In order to structure your program into different files, Node.js provides you with the simple module system. To use this module system you need to use require() which is used to imports the contents from another JavaScript file. # Let's begin. First, begin by installing Node.js from [Nodejs.org](https://nodejs.org/en/download/). Once you have that installed you can check for the version of node.js by using the node v command in the node.js command prompt as shown below.  # Create your own discord bot To do this next step we must visit [Discord App Developer Here](https://discordapp.com/developers/applications/me) and start a new app. In the example below the app is called I am a bot. You can call yours whatever it is that you like.  There are several things for you to do after that such as adding a bot description but for now, we will leave that and move on to the next step which is to create a bot user.  After that, you will receive a user ID and a Token ID. Please keep these safe. Then click on Public Bot so that it can be added t any server.  Now that the bot is created let's move on to write some Node.js code. # Node.js Now we need to create a package.json file. The file package is shown below. To interact with the discord app will be using the discord.js node.js module.   The content of the index.js file is **var Discordie = require('discordie'); var request = require('request'); var Events = Discordie.Events; var client = new Discordie(); client.connect({ token: 'Your Bot Token' }) client.Dispatcher.on(Events.GATEWAY_READY, e => { console.log('Connected as: '+ client.User.username); }); client.Dispatcher.on(Events.MESSAGE_CREATE, e => { var content = e.message.content; if(content.indexOf("$price ") == 0) { var coin = content.replace("$price ", ""); var value = ''; try{ request('http://api.coinmarketcap.com/v1/ticker/' + coin + '/', function(error,res,body) { var obj = JSON.parse(body); console.log(obj[0]); if(obj[0] === undefined) { e.message.channel.sendMessage("You have entered a wrong id"); } else { value = coin.toUpperCase() + " : Current Price " + obj[0].price_usd + " | 24hr Percentage Change " + obj[0].percent_change_24h; e.message.channel.sendMessage(value); } }); } catch (err) { e.message.channel.sendMessage("Wrong ID, Have a Great Day"); } } });** In the first code above use the Bot Token of your app to connect the Dicord Client. After that it will emit an event and write it to the console that your bot is connected to. Next we will run the index.js file using command node index.js as shown below:  This will check the cryptocurrency that the user has typed after the $price and will return the price of that cryptocurrency using the coin market api. # How to add the bot to the server. Once we have completed all of that we need to connect the bot to the server. You will need the client ID of your bot for this part. Add the ID to the URL below: <https://discordapp.com/oauth2/authorize?&client_id=ClientId&scope=bot> When you open that page it should ask you which server you wish to connected the bot to if you had done everything correctly. You will only be able to connect the bot to servers which you are managing and only servers which you manage will be shown. Once it is added you will be able to see the bot that you have created. You can play around with it and test it out.  This is a very basic app but it's enough to get you started. Thank you for reading. I want to point out that while I paraphrase this content most of it is paraphrased from [here](https://steemit.com/technology/@codingdefined/let-s-learn-how-to-create-a-discord-bot). The images are sourced from the same place. Despite that, this content was four months old and probably lost in 1000s of other steemit posts so it's a perfect time for an update. Please comment below and let me know your thoughts, and/or suggestions. Credits @codingdefined.
👍 samantha16, rodonlegend, kingwazza, kinganima, jeanpi1908, mk40, remlaps, cub2, remlaps2, jacek-w, steemitboard, fudz,