<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Vishnu Dileesh</title>
    <description>The latest articles on Forem by Vishnu Dileesh (@vic0de).</description>
    <link>https://forem.com/vic0de</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F449121%2F29a38129-0b14-47d1-a3c3-bf4c8a6efaf3.png</url>
      <title>Forem: Vishnu Dileesh</title>
      <link>https://forem.com/vic0de</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/vic0de"/>
    <language>en</language>
    <item>
      <title>Deploying a Nodejs project to Railway</title>
      <dc:creator>Vishnu Dileesh</dc:creator>
      <pubDate>Thu, 28 Sep 2023 07:50:40 +0000</pubDate>
      <link>https://forem.com/vic0de/deploying-a-nodejs-project-to-railway-511i</link>
      <guid>https://forem.com/vic0de/deploying-a-nodejs-project-to-railway-511i</guid>
      <description>&lt;p&gt;We will deploy the &lt;a href="https://vic0de.com/nodejs-discord-bot-create-github-issues-with-slash-commands" rel="noopener noreferrer"&gt;discord bot&lt;/a&gt; we created in our previous article. Railway gives a seamless deployment experience.&lt;/p&gt;

&lt;p&gt;Visit their &lt;a href="https://railway.app/?referralCode=I5697z" rel="noopener noreferrer"&gt;website&lt;/a&gt; and click login, and in the pop-up, choose GitHub or Email sign-in option. If you choose GitHub, in the next step click on the button that says Authorize Railway App.&lt;/p&gt;

&lt;p&gt;And done, you have now created an account with &lt;a href="https://railway.app/?referralCode=I5697z" rel="noopener noreferrer"&gt;Railway&lt;/a&gt; through GitHub.&lt;/p&gt;

&lt;p&gt;Now in the dashboard click on New Project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695883174720%2Ffc651faf-3288-40bf-b3cd-48453cca314e.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695883174720%2Ffc651faf-3288-40bf-b3cd-48453cca314e.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And in the pop-up select Deploy from GitHub repo in our case. Our Discord bot project is a public GitHub project - &lt;a href="https://github.com/VishnuDileesh/GithubDiscordBot" rel="noopener noreferrer"&gt;GitHubDiscordBot&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695883677257%2Fc5aef63e-0ba3-4bc8-a6d7-18e5a8fe86d1.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695883677257%2Fc5aef63e-0ba3-4bc8-a6d7-18e5a8fe86d1.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the next step click on Configure GitHub App, and a pop-up will open with GitHub asking you to select where to install the Railway App. Select your account.&lt;/p&gt;

&lt;p&gt;Next, choose the permissions and access controls. Then for the last step click on the green button that says Install &amp;amp; Authorize.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695883791132%2F47f4c11d-79ce-4847-8669-c2cd02001a45.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695883791132%2F47f4c11d-79ce-4847-8669-c2cd02001a45.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you will be back in your dashboard. Give a refresh and if you click on the New Project again and choose Deploy from GitHub, it will load repositories from your GitHub account.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695883978076%2F693a0223-0484-4f68-97ff-df06d0854b75.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695883978076%2F693a0223-0484-4f68-97ff-df06d0854b75.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select the project you want to deploy. And in the next step, you can deploy straight away or choose to add the needed environment variables.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695884067088%2F81ed480d-4fe0-423c-aac0-c3f497736751.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695884067088%2F81ed480d-4fe0-423c-aac0-c3f497736751.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you click on either of those options, a new project will be created in Railway with your chosen GitHub project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695884135583%2F404d3af3-2850-4a45-b33e-37e09cd7da33.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695884135583%2F404d3af3-2850-4a45-b33e-37e09cd7da33.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here you can add your environment variables. In my case, I will add the variables listed in the .env_example file in the project GitHub folder.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695884250409%2F3834a6a3-b9af-458c-a668-bb3c57b99275.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695884250409%2F3834a6a3-b9af-458c-a668-bb3c57b99275.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the Settings page, you can choose the branch you wish to deploy. And other details like what should the start command be.&lt;/p&gt;

&lt;p&gt;In my case, I added the start command as&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;npm run start&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695884457065%2Fa013df00-3525-47d3-9acc-89358fe76241.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695884457065%2Fa013df00-3525-47d3-9acc-89358fe76241.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each time you make changes here in the project dashboard, like adding or removing an environment variable, or pushing a new update to the project GitHub repo, Railway will re-build the project and will deploy again.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695884771804%2Fba84e614-b10a-467f-8551-ea04ba1c9601.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695884771804%2Fba84e614-b10a-467f-8551-ea04ba1c9601.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the Deployments, you can see your past deployment and the one running now. If you click on the View Logs button you can see different logs like Build Logs and Deploy Logs, and other details.&lt;/p&gt;

&lt;p&gt;In the settings, you can also choose the deployment region, generate a domain, or add a custom domain, and other major changes can be made.&lt;/p&gt;

&lt;p&gt;And that's it, you now have your project running live on &lt;a href="https://railway.app/?referralCode=I5697z" rel="noopener noreferrer"&gt;Railway&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695885280016%2F47743653-3527-4db9-89d8-4eac784aa88a.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695885280016%2F47743653-3527-4db9-89d8-4eac784aa88a.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>discord</category>
      <category>deploy</category>
      <category>railwayapp</category>
      <category>hosting</category>
    </item>
    <item>
      <title>Node.js Discord Bot: Create GitHub Issues with Slash Commands</title>
      <dc:creator>Vishnu Dileesh</dc:creator>
      <pubDate>Thu, 28 Sep 2023 07:49:11 +0000</pubDate>
      <link>https://forem.com/vic0de/nodejs-discord-bot-create-github-issues-with-slash-commands-2il2</link>
      <guid>https://forem.com/vic0de/nodejs-discord-bot-create-github-issues-with-slash-commands-2il2</guid>
      <description>&lt;p&gt;A Discord bot that can help you create Github issues from the Discord chat via Slash Commands, let's begin.&lt;/p&gt;

&lt;p&gt;We will be using &lt;a href="https://nodejs.org" rel="noopener noreferrer"&gt;Nodejs&lt;/a&gt; to build the bot while using the &lt;a href="https://github.com/discordjs/discord.js" rel="noopener noreferrer"&gt;discord.js&lt;/a&gt; library. For the bot to talk to GitHub we will be using the GitHub-provided SDK &lt;a href="https://github.com/octokit/octokit.js#readme" rel="noopener noreferrer"&gt;Octokit&lt;/a&gt;. To deal with environment variables we will be using the npm package &lt;a href="https://www.npmjs.com/package/dotenv" rel="noopener noreferrer"&gt;Dotenv&lt;/a&gt;. The Octokit SDK that will talk to GitHub needs a fetch package, for that we will be installing the package &lt;a href="https://www.npmjs.com/package/node-fetch" rel="noopener noreferrer"&gt;Node Fetch&lt;/a&gt;. We will be using two more libraries to be able to enable slash commands, &lt;a href="https://www.npmjs.com/package/@discordjs/rest" rel="noopener noreferrer"&gt;@discordjs/rest&lt;/a&gt; and &lt;a href="https://www.npmjs.com/package/@discordjs/builders" rel="noopener noreferrer"&gt;@discordjs/builders&lt;/a&gt;. Also, let's install another package named discord-api-types for type definitions.&lt;/p&gt;

&lt;p&gt;That was all about installing packages. Now we will move on to some actual coding.&lt;/p&gt;

&lt;p&gt;Create a project folder with your bot project name. And do npm init, to initialize npm.&lt;/p&gt;

&lt;p&gt;NPM is our package manager and all the packages we talked about will be installed through npm commands.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;dotenv discord.js @discordjs/rest @discordjs/builders discord-api-types/v10 node-fetch octokit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above command will install the needed packages. Now visit the package.json file which was auto-generated while we did npm init. There check to see if "main" is pointing to "index.js". Also while we are in here add the line "type": "module" to enable &lt;a href="https://www.javascripttutorial.net/es6/" rel="noopener noreferrer"&gt;ES6 modules&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The finished package.json will look like below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"yourbotname"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1.0.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"main"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"index.js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"module"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we create another file named .env, this file will have the environment variables. The secrets that we don't want anyone to see.&lt;/p&gt;

&lt;p&gt;Just because we are on the topic of secrets, and if you have plans to push the code to GitHub, never push this file .env to GitHub. For that create another file named &lt;a href="https://www.freecodecamp.org/news/gitignore-file-how-to-ignore-files-and-folders-in-git/" rel="noopener noreferrer"&gt;.gitignore&lt;/a&gt;, so that when you do git add and git commit, the .env file is ignored.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Moving on to the .env file, the file will have the following environment variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BOT_TOKEN=&amp;lt;your-bot-token-from-discord-application&amp;gt;
DISCORD_CLIENT_ID=&amp;lt;your-application-client-id&amp;gt;
DISCORD_GUILD_ID=&amp;lt;your-server-id&amp;gt;
GITHUB_AUTH_TOKEN=&amp;lt;your-github-auth-pat-token&amp;gt;
GITHUB_USERNAME=&amp;lt;your-github-username&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before jumping in and creating the index.js file and getting going with coding. Let's figure out how to get BOT_TOKEN, DISCORD_CLIENT_ID, DISCORD_GUILD_ID, and GITHUB_AUTH_TOKEN.&lt;/p&gt;

&lt;p&gt;First, let's dive in for the BOT_TOKEN. For that visit the &lt;a href="https://discord.com/developers/applications" rel="noopener noreferrer"&gt;Discord Developer Portal&lt;/a&gt; and on the Application page, click on the giant "Blurple" colored button that says New Application.&lt;/p&gt;

&lt;p&gt;Before that if you have not turned on the Developer Mode. Please do so by clicking on the gear icon next to your username to get to the User Settings page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695786781815%2Fbc2c9de7-5065-4ca5-b6a2-ee5fbac95692.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695786781815%2Fbc2c9de7-5065-4ca5-b6a2-ee5fbac95692.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There scroll a bit down while keeping an eye on the left panel items to find the one named Advanced. And then turn that Developer Mode on to become a Developer.&lt;/p&gt;

&lt;p&gt;Now that you are a Developer and have the Developer permissions, let's continue with creating a new application.&lt;/p&gt;

&lt;p&gt;In the pop-up appearing after clicking the New Application button while you were on the Developer Portal. Enter your dream bot project name (Discord doesn't allow the naming of bots with names containing words like discord, bot, etc.). Select the check box and then proceed by clicking the button that says Create.&lt;/p&gt;

&lt;p&gt;On the page that opens after the bot is created. There on the General Information page, you can beautify your bot by adding a profile picture and such.&lt;/p&gt;

&lt;p&gt;Then move your eyes through the menu items listed under General Information on the left side panel. Then click on Bot.&lt;/p&gt;

&lt;p&gt;While on the page, turn that Public Bot option off, if you don't want people other than you using the bot. Initially, you won't see the Token listed like in the screenshot. But then you will see the Reset Token button, click on that and proceed. And there you will have your Token displayed. Remember it's a secret, a deep secret to be kept secret. Don't ever take a screenshot of that Token post it on a blog article for the world to see.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695787407824%2F89d5b827-59b2-4ee4-a026-a5b60e503f5a.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695787407824%2F89d5b827-59b2-4ee4-a026-a5b60e503f5a.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy the TOKEN and paste it into your .env file corresponding to BOT_TOKEN. And keep it a secret.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BOT_TOKEN=MTE1NjQzOTgxNDQ2NDM0MDAxOQ.Gixlqs.HZlLAsfqaQdECiAgQ5v7UE3uec5eoYazliDW1M
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then scroll a bit and under the Privileged Gateway Intents, turn on the option for Message Content Intent. This will allow your bot to see the chat message contents happening on your server.&lt;/p&gt;

&lt;p&gt;Now again gaze your eyes through the left panel and click on OAuth2, which is above Bot on the side panel. Here copy CLIENT ID displayed under Client Information.&lt;/p&gt;

&lt;p&gt;Then click on URL Generator, which will be in the dropdown that just opened while you clicked OAuth2.&lt;/p&gt;

&lt;p&gt;On the screen, where a giant box of checkboxes with scops appears, click the checkmark for bot. Now that would have opened another giant box of checkboxes with Bot Permissions. Here select Administrator. (It is best practice to only provide the permissions that you really intend to use for security purposes.)&lt;/p&gt;

&lt;p&gt;Now scrolling to a bit bottom, you will see a URL. That's the generated URL for you to invite your bot to your server. Copy and paste the URL into a new tab of your browser.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695788241077%2F811027b2-e3a6-4265-8a50-6335fd78071f.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695788241077%2F811027b2-e3a6-4265-8a50-6335fd78071f.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On the page that opens select a Server of your choice in which you intend to add the bot. Click Continue. A confirmation page opens asking if you are sure about the permissions that you are giving to this newly born bot. If you are good with it, then click Authorize.&lt;/p&gt;

&lt;p&gt;Done, there in you get a success message of your bot being added to the server. Now if you go to your Server and check the members list you will see your bot listed.&lt;/p&gt;

&lt;p&gt;Now let's dive back into coding, the bot, and deploying it.&lt;/p&gt;

&lt;p&gt;In the index.js file, we will start by doing the imports of the packages we installed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dotenv/config&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Octokit&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;octokit&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;fetch&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;node-fetch&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;GatewayIntentBits&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;discord.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;REST&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@discordjs/rest&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Routes&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;discord-api-types/v10&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;SlashCommandBuilder&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@discordjs/builders&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we will initialize both Discord client.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;intents&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nx"&gt;GatewayIntentBits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Guilds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;GatewayIntentBits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;GuildMessages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;GatewayIntentBits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;MessageContent&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now to do the same for Ocktokit, that is to initialize Octkokit. We need GitHub PAT (Personal Access Token)&lt;/p&gt;

&lt;p&gt;Log in to GitHub and then click on your profile, in the menu, scroll down and select Settings. Now in on your profile page, scroll to the bottom to find the Developer Settings link. That is on the left panel, the last item.&lt;/p&gt;

&lt;p&gt;Now you will see a page with GitHub Apps, OAuth Apps, and Personal Access Tokens.&lt;/p&gt;

&lt;p&gt;We know what to click here, select Personal Access tokens. In the newly opened sub-menu of items under PAT, click on Tokens (Classic).&lt;/p&gt;

&lt;p&gt;On the page, click, Generate New Token and again go for the option of Classic. Now we have to enter a note to understand why created this token when we come back in the future. Then select an expiration for the bot from the dropdown selection. Then we are to carefully select the permissions we need for the bot to work with GitHub with this newly generated access token.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695789284553%2Fc7710553-91df-447b-ad43-9d0a913607a2.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695789284553%2Fc7710553-91df-447b-ad43-9d0a913607a2.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then we click on the green button at the bottom that says Generate Toke&lt;/p&gt;

&lt;p&gt;On the next opened screen, copy your personal access token. It's a one-time thing, you won't be able to see the token again on this page. So save it in your .env, and keep it away from spying eyes. Never share it with anyone.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BOT_TOKEN=MTE1NjQzOTgxNDQ2NDM0MDAxOQ.Gixlqs.HZlLAsfqaQdECiAgQ5v7UE3uec5eoYazliDW1M
DISCORD_CLIENT_ID=7951522907057725878
GITHUB_ACCESS_TOKEN=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
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we have got Personal Access Token from GitHub, let's now initialize Octokit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;octokit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Octokit&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;GITHUB_AUTH_TOKEN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;fetch&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we are passing the token from our environment to the auth parameter on the initialization. And also we are setting fetch as our choice request handler for Octokit.&lt;/p&gt;

&lt;p&gt;Now we will add a listener to know when our discord client is connected and ready to go ahead and listen for messages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ready&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Logged in as MyNewBot!`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Okay, so we have our client-ready code done, which will do a console log, we have our bot token, client ID, and GitHub personal access token.&lt;/p&gt;

&lt;p&gt;Now we need the server ID, which you can find by right-clicking on your server name. Then select the last item in the opened menu which says Copy Server ID. Now paste the server ID in the .env file in correspondence to the variable DISCORD_GUILD_ID, and then we are good to go.&lt;/p&gt;

&lt;p&gt;We will go back to index.js file. Under the client initialization, we will create a new variable rest and initialize it with the discord rest package we installed by providing the bot token from our .env file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;rest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;REST&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;10&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nf"&gt;setToken&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;BOT_TOKEN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we will create our commands in a variable of an array named commands. Find more about command building in the &lt;a href="https://discordjs.guide/creating-your-bot/slash-commands.html" rel="noopener noreferrer"&gt;docs provided by discord&lt;/a&gt;. We will have two main commands for creating an issue and another command to get all issues.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;commands&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SlashCommandBuilder&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;issue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setDescription&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;To deal with github issues&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addSubcommand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;subcommand&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
      &lt;span class="nx"&gt;subcommand&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;create&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setDescription&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Create a new issue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addStringOption&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;option&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
          &lt;span class="nx"&gt;option&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;project&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setDescription&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Project name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setRequired&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addStringOption&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;option&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
          &lt;span class="nx"&gt;option&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setDescription&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Issue title&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setRequired&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addStringOption&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;option&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
          &lt;span class="nx"&gt;option&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;description&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setDescription&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Issue description&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setRequired&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addSubcommand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;subcommand&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
      &lt;span class="nx"&gt;subcommand&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;get&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setDescription&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Get all issues from project&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addStringOption&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;option&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
          &lt;span class="nx"&gt;option&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;project&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setDescription&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Project name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setRequired&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toJSON&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we have our commands ready, we will write an anonymous function that will invoke at the start of the server and will send the discord server our commands.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Started refreshing application (/) commands.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;rest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nx"&gt;Routes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;applicationGuildCommands&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DISCORD_CLIENT_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DISCORD_GUILD_ID&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;commands&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Successfully reloaded application (/) commands.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})()&lt;/span&gt;

&lt;span class="cm"&gt;/*
The client id and guild id we have in the .env file are passed here
in the arguments along with commands we created in the value of body.
*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Like we listened for client-ready we will listen for interactions. For that we will use interactionCreate listener and inside we will return without doing anything if the interaction.isCommand check returns false.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;interactionCreate&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;interaction&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;interaction&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isCommand&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;commandName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;interaction&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;commandName&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;issue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;subcommand&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getSubcommand&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;subcommand&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;create&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;projectName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;project&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;issueTitle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;issueDescription&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;description&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

      &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;octokit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;issues&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
          &lt;span class="na"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;GITHUB_USERNAME&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;repo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;projectName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;issueTitle&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;issueDescription&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;interaction&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="s2"&gt;`Issue created in &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;projectName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; repository with title &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;issueTitle&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
          Issue URL: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;html_url&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
          `&lt;/span&gt;
          &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;err::: &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;subcommand&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;get&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;projectName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;project&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

      &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;octokit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;issues&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listForRepo&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;GITHUB_USERNAME&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;repo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;projectName&lt;/span&gt;
      &lt;span class="p"&gt;})&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;data::: &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

          &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;issues&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;issue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;issue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;html_url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

          &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;interaction&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="s2"&gt;`Fetching issues from &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;projectName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; repository:
          Done:
          &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;issues&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;
          `&lt;/span&gt;
          &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;err::: &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we know it's a command and we extract the command name, options from the variable "interact" that we receive in the callback. Then we proceed with our if checks and the steps to create issues and fetch issues with the package Octokit.&lt;/p&gt;

&lt;p&gt;That's it, we are all set. The only thing that we need to do now is let the bot client login by passing the bot token.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;login&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;BOT_TOKEN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now &lt;a href="https://vic0de.com/deploying-a-nodejs-project-to-railway" rel="noopener noreferrer"&gt;deploy&lt;/a&gt; the bot, visit your discord server, and type / in the chat and see your commands coming alive. Select and enter the parameters. You will receive a reply from the bot telling of its new creation of an issue on your provided repository. Or the list of issues it fetches based on your provided project name.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695877174267%2F54a38a30-b00b-4531-b9da-8f25bf26016a.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695877174267%2F54a38a30-b00b-4531-b9da-8f25bf26016a.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The easiest forms of deployments are through &lt;a href="https://www.heroku.com/" rel="noopener noreferrer"&gt;Heroku&lt;/a&gt; or &lt;a href="https://railway.app?referralCode=I5697z" rel="noopener noreferrer"&gt;Railway&lt;/a&gt;.&lt;br&gt;&lt;br&gt;
Full source code: &lt;a href="https://github.com/VishnuDileesh/GithubDiscordBot" rel="noopener noreferrer"&gt;GithubDiscordBot&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>discord</category>
      <category>node</category>
      <category>github</category>
      <category>coding</category>
    </item>
    <item>
      <title>Creating a Discord bot in Nodejs: Create GitHub issues from Discord Chat</title>
      <dc:creator>Vishnu Dileesh</dc:creator>
      <pubDate>Thu, 28 Sep 2023 07:44:43 +0000</pubDate>
      <link>https://forem.com/vic0de/creating-a-discord-bot-in-nodejs-create-github-issues-from-discord-chat-1j93</link>
      <guid>https://forem.com/vic0de/creating-a-discord-bot-in-nodejs-create-github-issues-from-discord-chat-1j93</guid>
      <description>&lt;p&gt;A Discord bot that can help you create Github issues from the Discord chat, let's begin. &lt;a href="https://vic0de.com/nodejs-discord-bot-create-github-issues-with-slash-commands" rel="noopener noreferrer"&gt;Discord bots can also be created to use slash commands, which gives a better user experience.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We will be using &lt;a href="https://nodejs.org" rel="noopener noreferrer"&gt;Nodejs&lt;/a&gt; to build the bot while using the &lt;a href="https://github.com/discordjs/discord.js" rel="noopener noreferrer"&gt;discord.js&lt;/a&gt; library. For the bot to talk to GitHub we will be using the GitHub-provided SDK &lt;a href="https://github.com/octokit/octokit.js#readme" rel="noopener noreferrer"&gt;Octokit&lt;/a&gt;. To deal with environment variables we will be using the npm package &lt;a href="https://www.npmjs.com/package/dotenv" rel="noopener noreferrer"&gt;Dotenv&lt;/a&gt;. The Octokit SDK that will talk to GitHub needs a fetch package, for that we will be installing the package &lt;a href="https://www.npmjs.com/package/node-fetch" rel="noopener noreferrer"&gt;Node Fetch&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;That was all about installing packages. Now we will move on to some real coding.&lt;/p&gt;

&lt;p&gt;Create a project folder with your bot project name. And do npm init, to initialize npm.&lt;/p&gt;

&lt;p&gt;NPM is our package manager and all the packages we talked about will be installed through npm commands.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;dotenv discord.js node-fetch octokit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above command will install the needed packages. Now visit the package.json file which was auto-generated while we did npm init. There check to see if "main" is pointing to "index.js". Also while we are in here add the line "type": "module" to enable &lt;a href="https://www.javascripttutorial.net/es6/" rel="noopener noreferrer"&gt;ES6 modules&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The finished package.json will look like below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"yourbotname"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1.0.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"main"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"index.js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"module"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we create another file named .env, this file will have the environment variables. The secrets that we don't want anyone to see.&lt;/p&gt;

&lt;p&gt;Just because we talked about secrets, and if you have plans to push the code to GitHub, never push this file .env to GitHub. For that create another file named &lt;a href="https://www.freecodecamp.org/news/gitignore-file-how-to-ignore-files-and-folders-in-git/" rel="noopener noreferrer"&gt;.gitignore&lt;/a&gt;, so that when you do git add and git commit, the .env file is ignored.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Moving on to the .env file, the file will have the following environment variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BOT_TOKEN=&amp;lt;your-bot-token-from-discord-application&amp;gt;
GITHUB_AUTH_TOKEN=&amp;lt;your-github-auth-pat-token&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before jumping in and creating the index.js file and getting going with coding. Let's figure out how to get BOT_TOKEN and GITHUB_AUTH_TOKEN.&lt;/p&gt;

&lt;p&gt;First, let's dive in for the BOT_TOKEN. For that visit the &lt;a href="https://discord.com/developers/applications" rel="noopener noreferrer"&gt;Discord Developer Portal&lt;/a&gt; and on the Application page, click on the giant "Blurple" colored button that says New Application.&lt;/p&gt;

&lt;p&gt;Before that if you have not turned on the Developer Mode. Please do so by clicking on the gear icon next to your username to get to the User Settings page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695786781815%2Fbc2c9de7-5065-4ca5-b6a2-ee5fbac95692.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695786781815%2Fbc2c9de7-5065-4ca5-b6a2-ee5fbac95692.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There scroll a bit down while keeping an eye on the left panel items to find the one named Advanced. And then turn that Developer Mode on to become a Developer.&lt;/p&gt;

&lt;p&gt;Now that you are a Developer and have the Developer permissions, let's continue with creating a new application.&lt;/p&gt;

&lt;p&gt;In the pop-up appearing after clicking the New Application button while you were on the Developer Portal. Enter your dream bot project name. Select the check box and then proceed by clicking the button that says Create.&lt;/p&gt;

&lt;p&gt;On the page that opens after the bot is created. There on the General Information page, you can beautify your bot by adding a profile picture and such.&lt;/p&gt;

&lt;p&gt;Then move your eyes through the menu items listed under General Information on the left side panel. Then click on Bot.&lt;/p&gt;

&lt;p&gt;While on the page, turn that Public Bot option off, if you don't want people other than you using the bot. Initially, you won't see the Token listed like in the screenshot. But then you will see the Reset Token button, click on that and proceed. And there you will have your Token displayed. Remember it's a secret, a deep secret to be kept secret. Don't ever take a screenshot of that Token post it on a blog article for the world to see.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695787407824%2F89d5b827-59b2-4ee4-a026-a5b60e503f5a.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695787407824%2F89d5b827-59b2-4ee4-a026-a5b60e503f5a.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy the TOKEN and paste it into your .env file corresponding to BOT_TOKEN. And keep it a secret.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BOT_TOKEN=MTE1NjQzOTgxNDQ2NDM0MDAxOQ.Gixlqs.HZlLAsfqaQdECiAgQ5v7UE3uec5eoYazliDW1M
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then scroll a bit and under the Privileged Gateway Intents, turn on the option for Message Content Intent. This will allow your bot to see the chat message contents happening on your server.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695787705450%2Fc9dba0ea-8368-42b9-94bc-855acff0173c.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695787705450%2Fc9dba0ea-8368-42b9-94bc-855acff0173c.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now again gaze your eyes through the left panel and click on OAuth2, which is above Bot on the side panel. Therein click on URL Generator, which will be in the dropdown that just opened while you clicked OAuth2.&lt;/p&gt;

&lt;p&gt;On the screen, where a giant box of checkboxes with scops appears, click the checkmark for bot. Now that would have opened another giant box of checkboxes with Bot Permissions. Here select Administrator. (It is best practice to only provide the permissions that you really intend to use for security purposes.)&lt;/p&gt;

&lt;p&gt;Now scrolling to a bit bottom, you will see a URL. That's the generated URL for you to invite your bot to your server. Copy and paste the URL into a new tab of your browser.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695788241077%2F811027b2-e3a6-4265-8a50-6335fd78071f.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695788241077%2F811027b2-e3a6-4265-8a50-6335fd78071f.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And on the page that opens select a Server of your choice in which you intend to add the bot. Click Continue. A confirmation page opens asking if you are sure about the permissions that you are giving to this newly born bot. If you are good with it, then click Authorize.&lt;/p&gt;

&lt;p&gt;Done, there in you get a success message of your bot being added to the server. Now if you go to your Server and check the members list you will see your bot listed.&lt;/p&gt;

&lt;p&gt;Now let's dive back into coding, the bot, and &lt;a href="https://vic0de.com/deploying-a-nodejs-project-to-railway" rel="noopener noreferrer"&gt;deploying&lt;/a&gt; it.&lt;/p&gt;

&lt;p&gt;In the index.js file, we will start by doing the imports of the packages we installed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dotenv/config&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Octokit&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;octokit&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;fetch&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;node-fetch&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;GatewayIntentBits&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;discord.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we will initialize both Discord client.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;intents&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nx"&gt;GatewayIntentBits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Guilds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;GatewayIntentBits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;GuildMessages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;GatewayIntentBits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;MessageContent&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now to do the same for Ocktokit, that is to initialize Octkokit. We need GitHub PAT (Personal Access Token)&lt;/p&gt;

&lt;p&gt;Log in to GitHub and then click on your profile, in the menu, scroll down and select Settings. Now in on your profile page, scroll to the bottom to find the Developer Settings link. That is on the left panel, the last item.&lt;/p&gt;

&lt;p&gt;Now you will see a page with GitHub Apps, OAuth Apps, and Personal Access Tokens.&lt;/p&gt;

&lt;p&gt;We know what to click here, select Personal Access tokens. In the newly opened sub-menu of items under PAT, click on Tokens (Classic).&lt;/p&gt;

&lt;p&gt;On the page, click, Generate New Token and again go for the option of Classic. Now we have to enter a note to understand why created this token when we come back in the future. Then select an expiration for the bot from the dropdown selection. Then we are to carefully select the permissions we need for the bot to work with GitHub with this newly generated access token.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695789284553%2Fc7710553-91df-447b-ad43-9d0a913607a2.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1695789284553%2Fc7710553-91df-447b-ad43-9d0a913607a2.png%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then we click on the green button at the bottom that says Generate Token.&lt;/p&gt;

&lt;p&gt;On the next opened screen, copy your personal access token. It's a one-time thing, you won't be able to see the token again on this page. So save it in your .env, and keep it away from spying eyes. Never share it with anyone.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BOT_TOKEN=MTE1NjQzOTgxNDQ2NDM0MDAxOQ.Gixlqs.HZlLAsfqaQdECiAgQ5v7UE3uec5eoYazliDW1M
GITHUB_ACCESS_TOKEN=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
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we have got Personal Access Token from GitHub, let's now initialize Octokit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;octokit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Octokit&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;GITHUB_AUTH_TOKEN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;fetch&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we are passing the token from our environment to the auth parameter on the initialization. And also we are setting fetch as our choice request handler for Octokit.&lt;/p&gt;

&lt;p&gt;Now we will add a listener to know when our discord client is connected and ready to go ahead and listen for messages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ready&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Logged in as MyNewBot!`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// we will also ! mark as our prefix to identify the message commands&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;prefix&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Okay, so we have our client ready code done, which will do a console log, we have our bot token, our GitHub personal access token, and the exclamation mark as a prefix set.&lt;/p&gt;

&lt;p&gt;We will do the on message listening to check if a message is our command to create some GitHub issues.&lt;br&gt;&lt;br&gt;
So how do we want the bot to work?&lt;/p&gt;

&lt;p&gt;The message should have a prefix of !. And then the word "mybot" or something like that to identify. Let's go with "gdbot" (GitHub Discord Bot?).&lt;/p&gt;

&lt;p&gt;And then we need arguments like repository name and issue name.&lt;/p&gt;

&lt;p&gt;So the message will look like:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;!gdbot my_repository_name issue_name_that_i_choose&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;messageCreate&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;author&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bot&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// if message is by a bot, ignore&lt;/span&gt;

  &lt;span class="c1"&gt;// checking if the message has a prefix to ensure it's our command&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prefix&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// remove the prefix from the message&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;commandBody&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prefix&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// then we split and turn the first item to lower case&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;commands&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;commandBody&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;command&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;commands&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;toLocaleLowerCase&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="c1"&gt;// other items in the message we will treat as argument&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;commands&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// !gdbot &amp;lt;repository name&amp;gt; &amp;lt;issue name&amp;gt;&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;command&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;gdbot&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;octokit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;issues&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;YourGitHubUsername&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;repo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Issue created using my new discord bot!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;})&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;channel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="s2"&gt;`Issue created in &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;&lt;span class="s2"&gt; repository with title &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;&lt;span class="s2"&gt; \n
          Issue URL: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;html_url&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;&lt;span class="s2"&gt; \n
          `&lt;/span&gt;
        &lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;})&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code, checks if the command is "gdbot". Then if it is, we proceed with creating an issue using the Octokit SDK where we will pass the owner parameter value as our GitHub username. And then the repository name as the first item in our extracted args variable. And title parameter value is the second item in the args, which is the issue name.&lt;/p&gt;

&lt;p&gt;When the issue is created successfully our bot will send in a message in the server channel, saying the issue has been created with a link to the newly created issue.&lt;/p&gt;

&lt;p&gt;Then below the code that does all the magic of listening to the command and creating an issue. We need to make the bot login with the bot token.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;login&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;BOT_TOKEN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it we have our bot ready. Now the next part is to &lt;a href="https://vic0de.com/deploying-a-nodejs-project-to-railway" rel="noopener noreferrer"&gt;deploy&lt;/a&gt; the project to a server.&lt;/p&gt;

&lt;p&gt;The easiest forms of deployments are through &lt;a href="https://www.heroku.com/" rel="noopener noreferrer"&gt;Heroku&lt;/a&gt; or &lt;a href="https://railway.app?referralCode=I5697z" rel="noopener noreferrer"&gt;Railway&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Full source code: &lt;a href="https://github.com/VishnuDileesh/GithubDiscordBot" rel="noopener noreferrer"&gt;GithubDiscordBot&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Linux Rice (Coder edition)</title>
      <dc:creator>Vishnu Dileesh</dc:creator>
      <pubDate>Sat, 21 Nov 2020 06:27:54 +0000</pubDate>
      <link>https://forem.com/vic0de/linux-rice-coder-edition-2mam</link>
      <guid>https://forem.com/vic0de/linux-rice-coder-edition-2mam</guid>
      <description>&lt;p&gt;Operating System: MX Linux&lt;br&gt;
Desktop Environment: XFCE&lt;br&gt;
Window Manager: i3wm&lt;br&gt;
Status bar: i3status&lt;br&gt;
Launcher: dmenu / rofi&lt;br&gt;
Notification: dunst&lt;br&gt;
File Manager: Thunar / NNN / Ranger&lt;br&gt;
Browser: QuteBrowser / Chrome / Firefox&lt;br&gt;
Text Editor: NeoVim / VS Code / Geany&lt;br&gt;
Terminal: xfce4-terminal / Hyper&lt;br&gt;
Shell: ZSH / BASH&lt;br&gt;
Word Processor: FeatherPad&lt;br&gt;
Document Viewer: mupdf&lt;br&gt;
Video Player: MPV / VLC&lt;br&gt;
Music Player: CMUS&lt;br&gt;
Podcast: Clementine&lt;br&gt;
Music Visualizer: CAVA&lt;br&gt;
Audio Controller: Pavucontrol&lt;br&gt;
Image Viewer: FEH / NOMACS&lt;br&gt;
Password Manager: ButterCup&lt;br&gt;
Screen Recorder: Kazam&lt;br&gt;
Screenshot: Flameshot&lt;br&gt;
System Info: Neofetch&lt;br&gt;
Process Viewer: htop&lt;br&gt;
Version Control: git&lt;br&gt;
Color Schemes: pywal&lt;br&gt;
Wallpapers: &lt;a href="https://www.instagram.com/codingwitharman/" rel="noopener noreferrer"&gt;IG acc: codingwitharman&lt;/a&gt; &lt;a href="https://drive.google.com/drive/folders/1xUwXUqFqshs3da1ppzOfecJM55AEhBxH" rel="noopener noreferrer"&gt;Wallpaper Drive&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;DOTFILES: &lt;a href="https://github.com/VishnuDileesh/linux-rice-coder-edition" rel="noopener noreferrer"&gt;Linux rice Coder Edition&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwhl9ylwyuc1s1wjeltsu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwhl9ylwyuc1s1wjeltsu.png" alt="Vishnu Dileesh Linux rice screenshot" width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>linux</category>
      <category>i3</category>
      <category>ricing</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Host nodejs Discord bot for free</title>
      <dc:creator>Vishnu Dileesh</dc:creator>
      <pubDate>Sun, 15 Nov 2020 06:54:12 +0000</pubDate>
      <link>https://forem.com/vic0de/host-nodejs-discord-bot-for-free-1hg3</link>
      <guid>https://forem.com/vic0de/host-nodejs-discord-bot-for-free-1hg3</guid>
      <description>&lt;p&gt;After going through the basic steps of setting up a bot in Discord's Application Dashboard &lt;a href="https://dev.to/vishnudileesh/building-a-discord-bot-basic-setups-4a53"&gt;Building a Discord Bot (Basic Setups)&lt;/a&gt; and inviting it to our server.&lt;/p&gt;

&lt;p&gt;We went ahead with coding the functionality of the bot&lt;br&gt;
&lt;a href="https://dev.to/vishnudileesh/build-a-discord-bot-using-nodejs-project-01-3npp"&gt;Build a Discord Bot using Nodejs - Project 01&lt;/a&gt; and our bot is all set to be hosted to the cloud.&lt;/p&gt;

&lt;p&gt;Well if you want to be a little fancy, you could also host your bot on a raspberry pi or you could host it on your laptop and set it to run 24/7.&lt;/p&gt;

&lt;p&gt;But for the sake of simplicity, we will be hosting our bot on Heroku in a free tier account. The hosting procedure will stay the same even if you use a paid tier or free tier. But in the case of the free tier, your bot has a quota limit of 550hours/month. So your bot will only stay online for roughly 22days in a month. Verifying your account with a credit card will add an extra 450hours to your quota. &lt;br&gt;
Or you could choose to go ahead with a hobby tier which costs around 7$ per month.&lt;/p&gt;

&lt;p&gt;So set up an account in Heroku, and will host our bot in a free tier.&lt;/p&gt;

&lt;p&gt;Before heading over to Heroku, let's first jump into our project folder and get it ready for hosting.&lt;/p&gt;

&lt;p&gt;Create a new file named Procfile &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Procfile is a file that specifies the commands that are executed by the app on startup. The file is needed by Heroku.&lt;br&gt;
The Procfile is always a simple text file that is named Procfile without a file extension. For example, Procfile.txt is not valid. &lt;br&gt;
&lt;a href="https://devcenter.heroku.com/articles/procfile" rel="noopener noreferrer"&gt;Check out the docs to know more&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;worker: node index.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Heroku offers two dynos web and worker, the web is suited for hosting web apps and the worker is for hosting scapers and bots. The difference is anything hosted on the web will take a small nap in-betweens, and in our scenario, we can't afford our bot to be sleeping while the user tries to invoke it, so we need to use the worker.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fa5plcwg5n9zxyspd84ck.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fa5plcwg5n9zxyspd84ck.png" alt="Alt Text" width="598" height="193"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Procfile will let Heroku know which dynos to activate.&lt;/p&gt;

&lt;p&gt;Now it is time to push your code to GitHub, make sure you have gitignored .env files or any file that contains secret tokens.&lt;/p&gt;

&lt;p&gt;After pushing your project code to GitHub, jump into the Heroku dashboard.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fntwfy8d0wbyehxtqahw7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fntwfy8d0wbyehxtqahw7.png" alt="Alt Text" width="800" height="109"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Inside the dashboard, click New and from the dropdown select create new app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2izoj9lg2asgjdmy6fvo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2izoj9lg2asgjdmy6fvo.png" alt="Alt Text" width="800" height="280"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now type in the app name of your choice, and check if it is available to use. If not available try out different combinations of names. If you want you could also pick and change the hosting region from the United States to Europe. Then click create app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzcxgjlol7xsuwiui5659.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzcxgjlol7xsuwiui5659.png" alt="Alt Text" width="800" height="315"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now on the app's dashboard page, click the connect to GitHub option.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F14f4soe9sgsst1s68npj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F14f4soe9sgsst1s68npj.png" alt="Alt Text" width="800" height="188"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After selecting Connect to GitHub option, you will be able to pick a GitHub account and a project repository to connect.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fhzd7o31v2vf5zng95cea.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fhzd7o31v2vf5zng95cea.png" alt="Alt Text" width="800" height="136"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Search for your project and click Connect to connect your project to Heroku.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1ensijedf0rvvs8g1fh5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1ensijedf0rvvs8g1fh5.png" alt="Alt Text" width="800" height="139"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on Deploy Branch under manual deploy, you could also use the automatic deploy option.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frvwn5w5azz1s4p3ghw0k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frvwn5w5azz1s4p3ghw0k.png" alt="Alt Text" width="800" height="257"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If it is all green ticks, well then things look pretty successful.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frwkdbw7biu99sj364ja3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frwkdbw7biu99sj364ja3.png" alt="Alt Text" width="800" height="339"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then navigate to the Overview page. You can see it says Build Successful and Deployed under Latest activity. But if you look to the left, under dyno formation. You can see Heroku has chosen the web as the default dyno. We need to change it to the worker to ensure the bot stays awake all the time under our free quota.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4a180j2nmnh15uq0a4s4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4a180j2nmnh15uq0a4s4.png" alt="Alt Text" width="800" height="157"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Navigate to the Resources page to change the running dyno. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fk73wqmgusfxof9itjr5y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fk73wqmgusfxof9itjr5y.png" alt="Alt Text" width="800" height="109"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3cdno6tz1bulrbbu4hdd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3cdno6tz1bulrbbu4hdd.png" alt="Alt Text" width="800" height="109"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on the edit button on the web dyno, then turn it off and click confirm.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5uraqo7rzb1cwbmfkg15.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5uraqo7rzb1cwbmfkg15.png" alt="Alt Text" width="800" height="112"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3px13w2ooq8uk5v8hu29.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3px13w2ooq8uk5v8hu29.png" alt="Alt Text" width="800" height="105"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now time to activate our worker dyno, click on the edit button on the worker dyno, then turn it on and click confirm.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fiyj10s8lkzq93285wsrh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fiyj10s8lkzq93285wsrh.png" alt="Alt Text" width="610" height="514"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On navigating back to the Overview page, now we can see the worker dyno is running successfully.&lt;/p&gt;

&lt;p&gt;And this is the moment, we expect to see our bot coming online in our server. But sadly on checking our discord server, we will see that the bot is still offline. Well, the issue is that the bot running on Heroku is not aware of the secret token needed for logging into our server. &lt;/p&gt;

&lt;p&gt;Remember the secret token is never pushed to GitHub so it is not available for the instance running on Heroku. So we need to pass the token to our instance from the dashboard.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fuczcy0lijauf57bh30i2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fuczcy0lijauf57bh30i2.png" alt="Alt Text" width="800" height="329"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Navigate to the Settings page, here you will see some of the information about our running app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2ut4j4ir289zpfxf1meu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2ut4j4ir289zpfxf1meu.png" alt="Alt Text" width="800" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Scroll down to the Config Vars section and click the Reveal Config Var button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzn5sandw1r11cl3rr816.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzn5sandw1r11cl3rr816.png" alt="Alt Text" width="800" height="194"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And here it says, There are no config vars for this app yet. Well, it is true, as we have not yet set any. But let's do that part now.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fag6r7uvhv65quwtguygj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fag6r7uvhv65quwtguygj.png" alt="Alt Text" width="800" height="203"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the place of Key use the one, we used in our .env file. In my case I used BOT_TOKEN and for the token value, you can find it in Discord's &lt;a href="https://discord.com/developers/applications/" rel="noopener noreferrer"&gt;Application Dashboard&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;And then click Add, and depending on your project, if you are using any other secrets token, also add them in here.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdghqalu8arjjzvtbydnx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdghqalu8arjjzvtbydnx.png" alt="Alt Text" width="800" height="140"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now navigate back to the Deploy page and click Deploy Branch again to make sure that the newly provided tokens are used by the bot.&lt;/p&gt;

&lt;p&gt;And that's it, your bot is live on the cloud, ready to serve your Discord server.&lt;/p&gt;

&lt;p&gt;If you are getting errors, no worries, errors are part of the journey. Google is your friend, try some googling and scavaging around StackOverflow.&lt;/p&gt;

&lt;p&gt;Still not able to resolve the error and get the bot working?&lt;br&gt;
Well free to connect and let's figure it out.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/vishnu-dileesh/" rel="noopener noreferrer"&gt;Connect on LinkedIn&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.instagram.com/vi_c0de/" rel="noopener noreferrer"&gt;Connect on Instagram&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Comment below your thoughts and bugs&lt;/p&gt;

&lt;p&gt;Happy Coding&lt;br&gt;
Keep Coding&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>discord</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Building Discord Bot using Nodejs - Project 01</title>
      <dc:creator>Vishnu Dileesh</dc:creator>
      <pubDate>Sat, 14 Nov 2020 16:16:15 +0000</pubDate>
      <link>https://forem.com/vic0de/build-a-discord-bot-using-nodejs-project-01-3npp</link>
      <guid>https://forem.com/vic0de/build-a-discord-bot-using-nodejs-project-01-3npp</guid>
      <description>&lt;p&gt;Project Idea: &lt;br&gt;
Inspiration quotes are as important as your daily dose of coffee to keep yourself motivated enough to deal with your day to day challenges.&lt;br&gt;
So let's build a bot, which gives a dose of random inspiration quote every time a user types in the command &lt;code&gt;!inspire&lt;/code&gt; in our discord server.&lt;/p&gt;

&lt;p&gt;The basic steps required to be done in the Discord's Application Dashboard before jumping into coding is written in the below-linked Article&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/vishnudileesh/building-a-discord-bot-basic-setups-4a53"&gt;Building a Discord Bot (Basic Setups)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Okay, so we have gone through all the steps mentioned in the above article. Now it's time to jump into doing some actual coding.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Step 1:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Open your terminal and create a new project folder.&lt;br&gt;
Inside the project folder initialize npm&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm init -y&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;When the initialization is done you will have a package.json file in your folder.&lt;/p&gt;

&lt;p&gt;Great now let's install discordjs and dotenv npm packages.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;discord.js is a powerful node.js module that allows you to interact with the Discord API very easily.&lt;/p&gt;

&lt;p&gt;Dotenv is a zero-dependency module that loads environment variables from a .env file into process.env.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Run the below command to install the packages&lt;br&gt;
&lt;code&gt;npm install discord.js dotenv&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Awesome, so now we have the packages installed.&lt;br&gt;
Now let's make two files in our project folder.&lt;br&gt;
This is the time to open the project in your choice of text editor.&lt;/p&gt;

&lt;p&gt;The first file is the .env file, We will store our bot token in this file. This file is never pushed to Github or not the content of the files is shared with anyone. Anyone who gets access to that secret token can log in to your server as the bot and can do malicious activities.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BOT_TOKEN=&amp;lt;copy-pasted-token-value-here&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3rllb42trx4xn2wc2wcr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3rllb42trx4xn2wc2wcr.png" alt="Alt Text" width="800" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The token is found on Discord's Application dashboard under the bot information page.&lt;/p&gt;

&lt;p&gt;Great, so now our .env file is all set. Let's move on to the real action.&lt;/p&gt;

&lt;p&gt;Create a new file named index.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Discord = require('discord.js')
const client = new Discord.Client()

const config = require('dotenv').config()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code, we are first importing the discord.js package, initializing it, and storing it in a constant named client.&lt;br&gt;
Then we are importing and activating dotenv to deal with our secrets.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const quotes = [
  'Chase the vision, not the money; the money will end up following you. — Tony Hsieh',
  'Don’t worry about failure; you only have to be right once. — Drew Houston',
  'Ideas are commodity. Execution of them is not. — Michael Dell',
  'If you are not embarrassed by the first version of your product, you’ve launched too late. — Reid Hoffman',
  'I knew that if I failed I wouldn’t regret that, but I knew the one thing I might regret is not trying. — Jeff Bezos',
]

const randomQuote = () =&amp;gt; quotes[Math.floor(Math.random() * quotes.length)]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Okay, now it's time to set up our inspirational quotes. If you want you could get innovative and use some available inspiration quotes API services. Here, am going humble, and gonna store the quotes in an Array named quotes. Also created a simple anonymous function named randomQuote to do some magic and pickup random quote from the array of quotes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;client.on('ready', () =&amp;gt; {
  console.log('Inspire Bot running')
  console.log(randomQuote())
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Client.on ready function lets us do stuff when the bot successfully logs in and is ready to go wild in our server. Here, am just console logging a message and a random quote because am superstitious. You could also get innovative and maybe make the bot add a message to your channel saying, the bot is all ready to spread some motivational vibes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const prefix = "!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Okay, so what is the prefix? Well, prefix could literally be anything. It is all about how we want our bot to be invoked by the users. Here we are going for the exclamation point, I might have just gone ahead with maybe a dollar symbol?. It doesn't matter, just choose one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;client.on('message', (msg) =&amp;gt; {

  if(msg.author.bot) return
  if(!msg.content.startsWith(prefix)) return

  const commandBody = msg.content.slice(prefix.length)

  const command = commandBody.toLowerCase()

  if(command === 'inspire'){
    msg.reply(randomQuote())
  }

})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just like client.on ready, client.on message, let us do some stuff when someone writes a message on our server. So, what do we wanna do, when a new message comes up?&lt;/p&gt;

&lt;p&gt;First, let's check if the author of the message is a bot. If so do nothing, stay quiet.&lt;/p&gt;

&lt;p&gt;Second, If the message doesn't start with a prefix (the exclamation point in our case) just ignore and do nothing.&lt;/p&gt;

&lt;p&gt;Third, let's extract the command from the message by removing the prefix from the start of the message. So if the message was !inspire, we will extract the word inspire and will store it in a variable named commandBody.&lt;/p&gt;

&lt;p&gt;Fourth, This is an optional step, oftentimes, your bot will have multiple commands to deal with so this step just allows you to do that check. So we are converting the commandBody to lowercase and storing it in a variable named command. Then we are doing an if check to see if the command is equal to the word inspire. Again you could come up with any command names, here am just choosing to call my command inspire. &lt;/p&gt;

&lt;p&gt;When the command is - inspire, we are replying to the message with our randomly generated inspirational quote.&lt;br&gt;
msg.reply will make sure that the bot replies directly to the user who invoked and asked for the inspirational vibe.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdjg0oppkwctpchy7yazf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdjg0oppkwctpchy7yazf.png" alt="Alt Text" width="800" height="157"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now our bot is all set to spread some inspirational vibes in our discord server. All that now required to do is to let the bot login to our server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;client.login(process.env.BOT_TOKEN)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bot needs the secret token to do the login. Remember we have the token all hidden on our .env file. To use it in our index.js file and pass it to client.login function we have earlier imported and activated dotenv package. That lets us call the token here without revealing it to anyone by calling process.env.BOT_TOKEN.&lt;/p&gt;

&lt;p&gt;To run the bot locally on your system, open your terminal in the project folder and run the below command&lt;/p&gt;

&lt;p&gt;&lt;code&gt;node index.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Also in the package.json file, we will add a start script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
 "start": "node index.js"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can run the bot by using either of the below commands&lt;/p&gt;

&lt;p&gt;&lt;code&gt;node index.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;or &lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm run&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once the bot successfully logs in and all ready to go, we will see our console message, also in the discord server, the bot will appear online.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Firz8375x5tohy4u92ax5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Firz8375x5tohy4u92ax5.png" alt="Alt Text" width="237" height="134"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Try invoking the bot by sending the below message to your discord server.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffg5ure8itd49azu5g3zl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffg5ure8itd49azu5g3zl.png" alt="Alt Text" width="800" height="62"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And if all went well, you will get an inspirational quoted reply from your bot. If you are getting errors, no worries, errors are part of the journey. Google is your friend, try some googling and scavaging around StackOverflow.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/VishnuDileesh/inspireBot" rel="noopener noreferrer"&gt;Full source code on GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Still not able to resolve the error and get the bot working?&lt;br&gt;
Well free to connect and let's figure it out.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/vishnu-dileesh/" rel="noopener noreferrer"&gt;Connect on LinkedIn&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.instagram.com/vi_c0de/" rel="noopener noreferrer"&gt;Connect on Instagram&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Comment below your thoughts and bugs&lt;/p&gt;

&lt;p&gt;Happy Coding&lt;br&gt;
Keep Coding&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>discord</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Building a Discord Bot (Basic Setups)</title>
      <dc:creator>Vishnu Dileesh</dc:creator>
      <pubDate>Thu, 12 Nov 2020 06:53:29 +0000</pubDate>
      <link>https://forem.com/vic0de/building-a-discord-bot-basic-setups-4a53</link>
      <guid>https://forem.com/vic0de/building-a-discord-bot-basic-setups-4a53</guid>
      <description>&lt;p&gt;Discord bots are a great way to add engagement to the servers. They are also fun to build and share with friends.&lt;/p&gt;

&lt;p&gt;I always love to keep the official docs open for quick reference&lt;br&gt;
&lt;a href="https://discordjs.guide/" rel="noopener noreferrer"&gt;https://discordjs.guide/&lt;/a&gt;&lt;br&gt;
This tutorial from Digital Ocean was very handy while I got started&lt;br&gt;
&lt;a href="https://www.digitalocean.com/community/tutorials/how-to-build-a-discord-bot-with-node-js#step-1-%E2%80%94-setting-up-a-discord-bot" rel="noopener noreferrer"&gt;Digital Ocean Nodejs Discord Bot - tutorial&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before jumping into coding, we first need to set up a discord bot using the &lt;a href="https://discord.com/developers/applications/" rel="noopener noreferrer"&gt;discord's application dashboard&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Create an App by clicking the button - New Application&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F36w4uujjs2d7d6j9z8k8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F36w4uujjs2d7d6j9z8k8.png" alt="Alt Text" width="800" height="438"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now click on the button - Bot&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fjjtcttzd8onadw0o8yxr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fjjtcttzd8onadw0o8yxr.png" alt="Alt Text" width="725" height="407"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On bot page - click on the button - Add Bot&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fkdgykis60mizymd2maei.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fkdgykis60mizymd2maei.png" alt="Alt Text" width="800" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we are on the newly added Bot page, here we can see information on our bot, including secrets like Token, which has to be kept a secret. They are never meant to be shared with anyone.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3rllb42trx4xn2wc2wcr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3rllb42trx4xn2wc2wcr.png" alt="Alt Text" width="800" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let's invite the bot to our server, click on the button - OAuth2. On the 0Auth2 page choose scope as bot and bot permissions as Administrator&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffbfj86i7unrmncncs409.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffbfj86i7unrmncncs409.png" alt="Alt Text" width="800" height="476"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy the link and paste it on a new tab in your browser, and select the server in which you want to add your newly born baby bot&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F944c82vs3caz61rsb3l6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F944c82vs3caz61rsb3l6.png" alt="Alt Text" width="800" height="387"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then approve the needed permissions for the bot to function on your server of choice and click Authorize&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ftquluripgbolgo5k9u0m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ftquluripgbolgo5k9u0m.png" alt="Alt Text" width="411" height="577"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ones Authorized, your bot is all set to bring joy to your Discord Server.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3hm9b5c587f3zhqd8z51.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3hm9b5c587f3zhqd8z51.png" alt="Alt Text" width="413" height="443"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the bot to be functional we need to do some actual coding&lt;br&gt;
In future posts, We will do a walkthrough of building Discord bots&lt;/p&gt;

&lt;p&gt;If you got any Discord Bot ideas, comment below&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>discord</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Serve scraped data through API— FastAPI</title>
      <dc:creator>Vishnu Dileesh</dc:creator>
      <pubDate>Sun, 27 Sep 2020 05:44:24 +0000</pubDate>
      <link>https://forem.com/vic0de/serve-scraped-data-through-api-fastapi-dc0</link>
      <guid>https://forem.com/vic0de/serve-scraped-data-through-api-fastapi-dc0</guid>
      <description>&lt;p&gt;In our &lt;a href="https://dev.to/vishnudileesh/python-web-scraping-requests-html-4lg0"&gt;previous&lt;/a&gt; project, we used python's requests-html library to scrape through the website (thehackernews.com) to go and fetch all the latest articles from every category. The project was just simply printing out the title &amp;amp; link of every article to the terminal.&lt;/p&gt;

&lt;p&gt;In this project, we will serve the scraped data through an API using python 's FastAPI framework. We will also do some tweaks to the way the scraping is done to make it easy to serve the data &amp;amp; in activating the scraping.&lt;/p&gt;

&lt;p&gt;So let's get started by cloning the &lt;a href="https://github.com/VishnuDileesh/THN_scraper" rel="noopener noreferrer"&gt;THN_scraper&lt;/a&gt; project to our system.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git clone https://github.com/VishnuDileesh/THN_scraper&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After moving into the folder, let's create a virtual environment to install our packages.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;python3 -m venv env&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;source env/bin/activate&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After activating the environment, let's install the needed packages from our requirements.txt&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pip3 install -r requirements.txt&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now let's try running the project by calling the following command in our terminal.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;python3 main.py&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frk0wlrv98jwfoe7qbjv3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frk0wlrv98jwfoe7qbjv3.png" alt="Alt Text" width="667" height="767"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On running the project we will get the above output in our terminal. Now that means we are all good with setting up our base project. Now let's get started in serving the data through API.&lt;/p&gt;

&lt;p&gt;We will start by renaming our main.py file to scraper.py&lt;/p&gt;

&lt;p&gt;Once the renaming is done we need to make few tweaks in our scraper.py file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def scrapeData():

    datas = []

    for category in categories:

        category = CategoryScrape(f'{baseURL}{category}', category)

        category.scrapeArticle()


def getScrapedData():

    return datas
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here, we are putting the scrape loop in a function named scrapeData, so that we could call the function from our API endpoint, to do the real scraping of the data. Also, we are creating another function named getScrapedData to receive the scraped data in our API endpoint to serve.&lt;/p&gt;

&lt;p&gt;Now, all our work is done here in the scraper.py file. Let's move forward by creating a new file named main.py, which will house all our API code.&lt;/p&gt;

&lt;p&gt;Let's not forget to install FastAPI and uvicorn in our project.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pip3 install fastapi uvicorn&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now when we have everything installed, let's also update our requirements.txt file to reflect our newly installed packages&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pip3 freeze &amp;gt; requirements.txt&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from fastapi import FastAPI, BackgroundTasks
from scraper import scrapeData, getScrapedData

app = FastAPI()


@app.get("/")
async def index():
    """ index route """

    return {
        "get-data": "visit /get-data to get scraped data",
        "scrape-data": "visit /scrape-data to activate scraping"
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;In our main.py, we start by importing FastAPI and BackgroundTasks from our installed fastapi framework. Then we need to import the functions scrapeData and getScrapedData from our scraper.py file.&lt;/p&gt;

&lt;p&gt;Then we create an app object by initializing the import FastAPI(), we start by creating our first route, which will simply return a very simple JSON response.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@app.get("/get-data")
async def get_data():
    """ Get all scraped data as in json by visiting /get-data """
    return getScrapedData()


@app.get("/scrape-data")
async def scrape_data(background_tasks: BackgroundTasks):
    """ On doing a get request to '/scrape-data' you Activates scraping """

    background_tasks.add_task(scrapeData)

    return {"Status": "Activated Scraping"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;In our get-data route, we call getScrapedData function, which was imported from scraper.py file. The route will return all the data we scraped from the website (thehackernews.com)&lt;/p&gt;

&lt;p&gt;In scrape-data route, we pass the scrapeData function, which we imported from scraper.py into the background_tasks. Which in return activates our scrapeData function, making the script run and do all the scraping magic to get the latest hacking news articles.&lt;/p&gt;

&lt;p&gt;Now, we have our API ready to be served on a web server. We will use uvicorn as our web server. Let's create a new file named run.py, which will have the webserver configuration.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
import uvicorn

if __name__ == "__main__":

    uvicorn.run("main:app",
                host='0.0.0.0',
                port=8000,
                reload=False,
                debug=False,
                workers=25)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here in our run.py file, we are importing our installed unicorn. And then we are initializing the file, calling the function uvicorn.run, in which we are passing in our app (which we initialized in main.py file), and also we are specifying host and port for uvicorn to serve. And we are setting reload and debug to false, as they are development settings. With the workers parameter we can set the number of workers to be run for the server to handle.&lt;/p&gt;

&lt;p&gt;So, that's all the code we needed for the project. Now we can go ahead and run the project by running the command in terminal&lt;/p&gt;

&lt;p&gt;&lt;code&gt;python3 run.py&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdhd7qvbmqbag3rljxeiw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdhd7qvbmqbag3rljxeiw.png" alt="Alt Text" width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Link to project GitHub repo:&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.dev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/VishnuDileesh" rel="noopener noreferrer"&gt;
        VishnuDileesh
      &lt;/a&gt; / &lt;a href="https://github.com/VishnuDileesh/THN_scraper_api" rel="noopener noreferrer"&gt;
        THN_scraper_api
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A web API that scrapes and list out latest articles in all categories from the website (thehackernews.com)
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;Happy Coding, Keep Coding&lt;br&gt;
&lt;a href="https://www.linkedin.com/in/vishnu-dileesh/" rel="noopener noreferrer"&gt;Connect with me on LinkedIn&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.instagram.com/vi_c0de/" rel="noopener noreferrer"&gt;Connect with me on Instagram&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>tutorial</category>
      <category>webdev</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Python web scraping — requests-html</title>
      <dc:creator>Vishnu Dileesh</dc:creator>
      <pubDate>Sat, 08 Aug 2020 11:33:52 +0000</pubDate>
      <link>https://forem.com/vic0de/python-web-scraping-requests-html-4lg0</link>
      <guid>https://forem.com/vic0de/python-web-scraping-requests-html-4lg0</guid>
      <description>&lt;p&gt;Web scraping is the process of extracting data from websites. To refine my skills I choose to do multiple projects using some of the awesome python libraries. For this project, we are using requests-html, which the creators describe as HTML parsing for humans.&lt;/p&gt;

&lt;p&gt;The project idea is very minimal and the goal is to get basics of using requests-html library. We are going to scrape through all categories in thehackernews.com website and get all the titles and links of the latest articles. To keep things simple, we are going to print out the story titles and links to the terminal.&lt;/p&gt;

&lt;p&gt;So let's get started by creating a new project folder (am naming the folder thn_scraper)&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mkdir thn_scraper&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Change into the folder and create a python virtual environment&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cd thn_scraper&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;python3 -m venv env&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Activate the environment &amp;amp; install the packages&lt;/p&gt;

&lt;p&gt;&lt;code&gt;source env/bin/activate&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pip3 install requests-html&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Let's start by creating file named main.py&lt;/p&gt;

&lt;p&gt;&lt;code&gt;nvim main.py&lt;/code&gt; (am using neovim, u can use any editor of your choice)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from requests_html import HTMLSession

session = HTMLSession()

baseURL = 'https://thehackernews.com/search/label/' 

categories = ['data%20breach', 'Cyber%20Attack', 'Vulnerability', 'Malware']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;First, we are importing HTMLSession function from the requests_html library we just installed. Also, we are initializing HTMLSession(). We also store the website URL to a variable baseURL. We are also storing the categories in a list.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class CategoryScrape():
    catURL = ''     
    r = ''
    def __init__(self, catURL, category):         
        print(f'Scraping starting on Category : {category} \n')  
        print(' ')         
        self.catURL = catURL         
        self.r = session.get(self.catURL)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here, we are creating class named CategoryScrape, which has initialization function which takes in two parameters catURL and category. We are also calling session.get in here, and passing the catURL. The response is then stored on a variable named r.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def scrapeArticle(self):         
        blog_posts = self.r.html.find('.body-post')         
        for blog in blog_posts:             
            storyLink = blog.find('.story-link', first=True).attrs['href']
            storyTitle = blog.find('.home-title', first=True).text
            print(storyTitle)
            print(storyLink)             
            print("\n")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The class also has a function named scrapeArticle, which has all bells and whistles to parse through the HTML and look for a list of articles and then scrape titles and links of individual articles. Once the data is scraped for each article, the story title and link are printed out into the terminal.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for category in categories:     
    category = CategoryScrape(f'{baseURL}{category}', category)
    category.scrapeArticle()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now, once we have the class and its functions ready, we are going to do a loop on for every category in the list named categories. And for in every loop, we will create a new object with the category name and will initialize it with the class, CategoryScrape. We also pass in the URL and category name. Then we call the scrape function on the object we created.&lt;br&gt;
So, all the code we needed for the project. Now we can go ahead and run the project by running the command in terminal&lt;/p&gt;

&lt;p&gt;&lt;code&gt;python3 main.py&lt;/code&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;




&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.dev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/VishnuDileesh" rel="noopener noreferrer"&gt;
        VishnuDileesh
      &lt;/a&gt; / &lt;a href="https://github.com/VishnuDileesh/THN_scraper" rel="noopener noreferrer"&gt;
        THN_scraper
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Happy Coding, Keep Coding&lt;br&gt;
&lt;a href="https://www.instagram.com/vi_c0de/" rel="noopener noreferrer"&gt;Connect with me on Instagram&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>html</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
