{"id":299888,"date":"2021-07-15T18:23:51","date_gmt":"2021-07-15T15:23:51","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/heres-how-to-build-an-interactive-discord-bot-in-under-60-minutes\/"},"modified":"2021-07-15T18:23:51","modified_gmt":"2021-07-15T15:23:51","slug":"heres-how-to-build-an-interactive-discord-bot-in-under-60-minutes","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/heres-how-to-build-an-interactive-discord-bot-in-under-60-minutes\/","title":{"rendered":"#Here\u2019s how to build an interactive Discord bot in under 60 minutes"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a373bcba49c5\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a373bcba49c5\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/heres-how-to-build-an-interactive-discord-bot-in-under-60-minutes\/#Before_we_begin%E2%80%A6\" >Before we begin\u2026<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/heres-how-to-build-an-interactive-discord-bot-in-under-60-minutes\/#Creating_a_new_Discord_bot\" >Creating a new Discord bot<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/heres-how-to-build-an-interactive-discord-bot-in-under-60-minutes\/#Adding_the_bot_to_a_Discord_server\" >Adding the bot to a Discord server<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/buradabiliyorum.com\/en\/heres-how-to-build-an-interactive-discord-bot-in-under-60-minutes\/#Implementing_the_bots_behavior\" >Implementing the bot\u2019s behavior<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/buradabiliyorum.com\/en\/heres-how-to-build-an-interactive-discord-bot-in-under-60-minutes\/#Log_in_and_start_listening_to_events\" >Log in and start listening to events<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/buradabiliyorum.com\/en\/heres-how-to-build-an-interactive-discord-bot-in-under-60-minutes\/#Reply_to_a_user_with_a_random_Dad_joke\" >Reply to a user with a random Dad joke<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/buradabiliyorum.com\/en\/heres-how-to-build-an-interactive-discord-bot-in-under-60-minutes\/#Search_for_a_Dad_joke_with_a_user-provided_search_term\" >Search for a Dad joke with a user-provided search term<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/buradabiliyorum.com\/en\/heres-how-to-build-an-interactive-discord-bot-in-under-60-minutes\/#Welcome_new_members\" >Welcome new members<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/buradabiliyorum.com\/en\/heres-how-to-build-an-interactive-discord-bot-in-under-60-minutes\/#Deploying_the_bot_to_Heroku\" >Deploying the bot to Heroku<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/buradabiliyorum.com\/en\/heres-how-to-build-an-interactive-discord-bot-in-under-60-minutes\/#Summary\" >Summary<\/a><\/li><\/ul><\/nav><\/div>\n<p>&#8220;<strong>#Here\u2019s how to build an interactive Discord bot in under 60 minutes<\/strong>&#8221;<\/p>\n<div><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/discord.com\/\">Discord<\/a><span>\u00a0<\/span>is a <span>instant messaging and digital distribution platform designed for creating communities. With over 100 million users, the service allows you to communicate with voice calls, video calls, text messaging, <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/social-mediaa\/\" data-internallinksmanager029f6b8e52c=\"1\" title=\"Social Media\" target=\"_blank\" rel=\"noopener\">media<\/a> and files in private chats, or ,as part of communities called \u201cservers\u201d.<\/span> With this<span>\u00a0<\/span><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/discord.com\/developers\/docs\/intro\">extensive <\/a>API,<span>\u00a0<\/span>Discord allows developers to build bots that perform repetitive, mundane, or even fun tasks. With a Discord bot, users can moderating and send messages to communities, as well as send private messages to users.<\/p>\n<p>In this tutorial, we will build a simple bot that sends random dad jokes to a community at a users request. Using Node.js and<span>\u00a0<\/span><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/discord.js.org\/#\/\">discord.js<\/a><span>\u00a0<\/span>module, we can create, develop, and deploy this Discord bot in less than 60 minutes.<\/p>\n<h2 id=\"before-we-begin\"><span class=\"ez-toc-section\" id=\"Before_we_begin%E2%80%A6\"><\/span>Before we begin\u2026<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>We\u2019ve listed all the things you need to set up before getting started with the tutorial:<\/p>\n<ul>\n<li>Install Node.js onto your machine.<\/li>\n<li>Create an account on Discord. You can either <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">download<\/a> the desktop app or access it using your browser.<\/li>\n<li><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/support.discord.com\/hc\/en-us\/articles\/204849977-How-do-I-create-a-server-\">Create a new community<\/a><span>\u00a0<\/span>(or a new \u201cserver\u201d in Discord language) to test the app.<\/li>\n<\/ul>\n<p>Once you are set up, you can begin the tutorial!<\/p>\n<p>One last thing, you can find the code for the project on<span>\u00a0<\/span><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/github.com\/anjaleeps\/dad-joke-discord-bot\">GitHub<\/a>.<\/p>\n<h2 id=\"creating-a-new-discord-bot\"><span class=\"ez-toc-section\" id=\"Creating_a_new_Discord_bot\"><\/span>Creating a new Discord bot<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In this first step, you should create and configure a new bot on Discord. Here\u2019s how you can do it:<\/p>\n<p>Log in to your Discord account and go to the application page on its developer portal.<\/p>\n<figure class=\"post-image post-mediaBleed aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360718 js-lazy\" alt=\"Discord Dev Portal\" width=\"700\" height=\"172\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord1.jpg\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord1.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord1-280x69.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord1-540x133.jpg 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord1-270x66.jpg 270w\"\/><figcaption>Credit: Author Provided<\/figcaption><figcaption><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/thenextweb.com\/news\/#\" data-url=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Feditorial.thenextweb.com%2Ftech%2F2021%2F07%2F15%2Fbuild-discord-bot-in-under-60-minutes-syndication%2F&amp;via=thenextweb&amp;related=thenextweb&amp;text=Check out this picture on: Discord Dev Portal.\" data-title=\"Share Discord Dev Portal. on Twitter\" data-width=\"685\" data-height=\"500\" class=\"post-image-share popitup\" title=\"Share Discord Dev Portal. on Twitter\"><i class=\"icon icon--inline icon--twitter--dark\"\/><\/a>Discord Dev Portal.<\/figcaption><noscript><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360718\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord1.jpg\" alt=\"Discord Dev Portal\" width=\"700\" height=\"172\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord1.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord1-280x69.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord1-540x133.jpg 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord1-270x66.jpg 270w\"\/><\/noscript><\/figure>\n<p><span>Click on \u201cNew Application.\u201d , this will generate a popup requesting the new bot\u2019s name.<\/span><\/p>\n<figure class=\"post-image post-mediaBleed aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1360719 js-lazy\" alt=\"Discord new application form\" width=\"566\" height=\"480\" sizes=\"auto, (max-width: 566px) 100vw, 566px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord2.jpg\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord2.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord2-248x210.jpg 248w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord2-319x270.jpg 319w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord2-159x135.jpg 159w\"\/><figcaption>Credit: Author Provided<\/figcaption><figcaption><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/thenextweb.com\/news\/#\" data-url=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Feditorial.thenextweb.com%2Ftech%2F2021%2F07%2F15%2Fbuild-discord-bot-in-under-60-minutes-syndication%2F&amp;via=thenextweb&amp;related=thenextweb&amp;text=Check out this picture on: Discord new application form.\" data-title=\"Share Discord new application form. on Twitter\" data-width=\"685\" data-height=\"500\" class=\"post-image-share popitup\" title=\"Share Discord new application form. on Twitter\"><i class=\"icon icon--inline icon--twitter--dark\"\/><\/a>Discord new application form.<\/figcaption><noscript><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1360719\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord2.jpg\" alt=\"Discord new application form\" width=\"566\" height=\"480\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord2.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord2-248x210.jpg 248w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord2-319x270.jpg 319w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord2-159x135.jpg 159w\"\/><\/noscript><\/figure>\n<p>After adding the name, click on the create button, and you\u2019ll be navigated to a new page with application information. From here, go to the \u201cBot\u201d tab and click \u201cAdd Bot\u201d to add the bot to the application. Again, confirm the action in the pop-up.<\/p>\n<figure class=\"post-image post-mediaBleed aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360720 js-lazy\" alt=\"Discord bot application\" width=\"700\" height=\"218\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord3.jpg\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord3.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord3-280x87.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord3-540x168.jpg 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord3-270x84.jpg 270w\"\/><figcaption><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/thenextweb.com\/news\/#\" data-url=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Feditorial.thenextweb.com%2Ftech%2F2021%2F07%2F15%2Fbuild-discord-bot-in-under-60-minutes-syndication%2F&amp;via=thenextweb&amp;related=thenextweb&amp;text=Check out this picture on: Discord bot application.\" data-title=\"Share Discord bot application. on Twitter\" data-width=\"685\" data-height=\"500\" class=\"post-image-share popitup\" title=\"Share Discord bot application. on Twitter\"><i class=\"icon icon--inline icon--twitter--dark\"\/><\/a>Discord bot application.<\/figcaption><noscript><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360720\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord3.jpg\" alt=\"Discord bot application\" width=\"700\" height=\"218\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord3.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord3-280x87.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord3-540x168.jpg 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord3-270x84.jpg 270w\"\/><\/noscript><\/figure>\n<p><span>This adds the new bot to Discord. Now, we can start configuring it.<\/span><\/p>\n<figure class=\"post-image post-mediaBleed aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360721 js-lazy\" alt=\"Discord register bot\" width=\"700\" height=\"269\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord4.jpg\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord4.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord4-280x108.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord4-540x208.jpg 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord4-270x104.jpg 270w\"\/><figcaption><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/thenextweb.com\/news\/#\" data-url=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Feditorial.thenextweb.com%2Ftech%2F2021%2F07%2F15%2Fbuild-discord-bot-in-under-60-minutes-syndication%2F&amp;via=thenextweb&amp;related=thenextweb&amp;text=Check out this picture on: Discord register bot.\" data-title=\"Share Discord register bot. on Twitter\" data-width=\"685\" data-height=\"500\" class=\"post-image-share popitup\" title=\"Share Discord register bot. on Twitter\"><i class=\"icon icon--inline icon--twitter--dark\"\/><\/a>Discord register bot.<\/figcaption><noscript><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360721\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord4.jpg\" alt=\"Discord register bot\" width=\"700\" height=\"269\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord4.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord4-280x108.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord4-540x208.jpg 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord4-270x104.jpg 270w\"\/><\/noscript><\/figure>\n<p>Now, we must copy the bot token and store it somewhere private. Remember: this token is for your eyes only; never share it with anyone else.<\/p>\n<p>Keep the default selections under the \u201cAuthorization Flow\u201d section.<\/p>\n<figure class=\"post-image post-mediaBleed aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360723 js-lazy\" alt=\"Discord authorization flow\" width=\"700\" height=\"158\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord5.jpg\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord5.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord5-280x63.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord5-540x122.jpg 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord5-270x61.jpg 270w\"\/><figcaption>Credit: Author Provided<\/figcaption><figcaption><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/thenextweb.com\/news\/#\" data-url=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Feditorial.thenextweb.com%2Ftech%2F2021%2F07%2F15%2Fbuild-discord-bot-in-under-60-minutes-syndication%2F&amp;via=thenextweb&amp;related=thenextweb&amp;text=Check out this picture on: Discord authorization flow.\" data-title=\"Share Discord authorization flow. on Twitter\" data-width=\"685\" data-height=\"500\" class=\"post-image-share popitup\" title=\"Share Discord authorization flow. on Twitter\"><i class=\"icon icon--inline icon--twitter--dark\"\/><\/a>Discord authorization flow.<\/figcaption><noscript><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360723\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord5.jpg\" alt=\"Discord authorization flow\" width=\"700\" height=\"158\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord5.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord5-280x63.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord5-540x122.jpg 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord5-270x61.jpg 270w\"\/><\/noscript><\/figure>\n<p><span>Next, you should turn on the\u201cServer Members Intent\u201d option under the \u201cPrivileged Gateway Intents.\u201d Our bot needs permission for this intent to detect when a new member joins the server.<\/span><\/p>\n<figure class=\"post-image post-mediaBleed aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360724 js-lazy\" alt=\"Discord set up bot intents\" width=\"700\" height=\"179\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord6.jpg\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord6.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord6-280x72.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord6-540x138.jpg 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord6-270x69.jpg 270w\"\/><figcaption>Credit: Author Provided<\/figcaption><figcaption><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/thenextweb.com\/news\/#\" data-url=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Feditorial.thenextweb.com%2Ftech%2F2021%2F07%2F15%2Fbuild-discord-bot-in-under-60-minutes-syndication%2F&amp;via=thenextweb&amp;related=thenextweb&amp;text=Check out this picture on: Discord set up bot intents.\" data-title=\"Share Discord set up bot intents. on Twitter\" data-width=\"685\" data-height=\"500\" class=\"post-image-share popitup\" title=\"Share Discord set up bot intents. on Twitter\"><i class=\"icon icon--inline icon--twitter--dark\"\/><\/a>Discord set up bot intents.<\/figcaption><noscript><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360724\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord6.jpg\" alt=\"Discord set up bot intents\" width=\"700\" height=\"179\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord6.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord6-280x72.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord6-540x138.jpg 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord6-270x69.jpg 270w\"\/><\/noscript><\/figure>\n<h2 id=\"adding-the-bot-to-a-discord-server\"><span class=\"ez-toc-section\" id=\"Adding_the_bot_to_a_Discord_server\"><\/span>Adding the bot to a Discord server<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>We should generate an invite link that reflects the level of permissions the bot should have to add it to a Discord server. To do this, go to the \u201cOAuth2\u201d tab on the same page and select \u201cbot\u201d as the application\u2019s scope. Then, choose the set of permissions the bot should have when interacting with the server. Our bot only needs permission to read and send messages in server channels.<\/p>\n<figure class=\"post-image post-mediaBleed aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1360725 js-lazy\" alt=\"Discord set bot permissions\" width=\"628\" height=\"542\" sizes=\"auto, (max-width: 628px) 100vw, 628px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord7.jpg\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord7.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord7-243x210.jpg 243w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord7-313x270.jpg 313w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord7-156x135.jpg 156w\"\/><figcaption>Credit: Author Provided<\/figcaption><figcaption><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/thenextweb.com\/news\/#\" data-url=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Feditorial.thenextweb.com%2Ftech%2F2021%2F07%2F15%2Fbuild-discord-bot-in-under-60-minutes-syndication%2F&amp;via=thenextweb&amp;related=thenextweb&amp;text=Check out this picture on: Discord set bot permissions.\" data-title=\"Share Discord set bot permissions. on Twitter\" data-width=\"685\" data-height=\"500\" class=\"post-image-share popitup\" title=\"Share Discord set bot permissions. on Twitter\"><i class=\"icon icon--inline icon--twitter--dark\"\/><\/a>Discord set bot permissions.<\/figcaption><noscript><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1360725\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord7.jpg\" alt=\"Discord set bot permissions\" width=\"628\" height=\"542\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord7.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord7-243x210.jpg 243w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord7-313x270.jpg 313w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord7-156x135.jpg 156w\"\/><\/noscript><\/figure>\n<p><span>After selecting all the necessary permissions, copy the URL generated under the scope section and open it in a new browser tab. Then, choose the server that the bot should join and authorize the action when prompted.<\/span><\/p>\n<figure class=\"post-image post-mediaBleed aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1360726 js-lazy\" alt=\"Connect bot to Discord server\" width=\"580\" height=\"772\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord8.jpg\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord8.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord8-158x210.jpg 158w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord8-203x270.jpg 203w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord8-102x135.jpg 102w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord8-687x916.jpg 687w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord8-414x552.jpg 414w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord8-354x472.jpg 354w\"\/><figcaption><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/thenextweb.com\/news\/#\" data-url=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Feditorial.thenextweb.com%2Ftech%2F2021%2F07%2F15%2Fbuild-discord-bot-in-under-60-minutes-syndication%2F&amp;via=thenextweb&amp;related=thenextweb&amp;text=Check out this picture on: Connect bot to Discord server.\" data-title=\"Share Connect bot to Discord server. on Twitter\" data-width=\"685\" data-height=\"500\" class=\"post-image-share popitup\" title=\"Share Connect bot to Discord server. on Twitter\"><i class=\"icon icon--inline icon--twitter--dark\"\/><\/a>Connect bot to Discord server.<\/figcaption><noscript><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1360726\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord8.jpg\" alt=\"Connect bot to Discord server\" width=\"580\" height=\"772\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord8.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord8-158x210.jpg 158w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord8-203x270.jpg 203w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord8-102x135.jpg 102w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord8-687x916.jpg 687w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord8-414x552.jpg 414w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord8-354x472.jpg 354w\"\/><\/noscript><\/figure>\n<p><span>Now, if you go to the Discord server, you\u2019ll be able to see the new bot listed on the right side panel.\u00a0<\/span><\/p>\n<h2 id=\"implementing-the-bots-behavior\"><span class=\"ez-toc-section\" id=\"Implementing_the_bots_behavior\"><\/span>Implementing the bot\u2019s behavior<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>We can now start adding code to define how the bot should behave inside the server. As we mentioned at the beginning, we will use Node.js and discord.js to do this.<\/p>\n<p>As the first step of implementation, set up a new Node.js project and initialize it with npm. Then, we should install discord.js, axios, and dotenv modules using npm.<\/p>\n<p>\u00a0<\/p>\n<p><code>npm install discord.js axios dotenv<\/code><\/p>\n<p><span>Next, we create a .env file and add the token we previously copied as an environment variable.\u00a0<\/span><\/p>\n<p>\u00a0<\/p>\n<pre><code class=\"language-text\">\/\/.env&#13;\n&#13;\nTOKEN=&lt;your token&gt;<\/code><\/pre>\n<h2 id=\"log-in-and-start-listening-to-events\"><span class=\"ez-toc-section\" id=\"Log_in_and_start_listening_to_events\"><\/span>Log in and start listening to events<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Now we can import discord.js and set up the bot to listen to server events and respond accordingly. Create a new file named index.js and add the following code to it.<\/p>\n<pre><code class=\"language-javascript\"><span>\/\/index.js&#13;\n<\/span><span>require<\/span>(<span>\"dotenv\"<\/span>).<span>config<\/span>();&#13;\n<span>const<\/span><span>Discord<\/span><span>=<\/span><span>require<\/span>(<span>\"discord.js\"<\/span>);&#13;\n<span>const<\/span><span>client<\/span><span>=<\/span><span>new<\/span><span>Discord<\/span>.<span>Client<\/span>();&#13;\n&#13;\n<span>\/\/Listen to the event that signals the bot is ready to start working&#13;\n<\/span><span>client<\/span>.<span>on<\/span>(<span>\"ready\"<\/span>, () =&gt; {&#13;\n  <span>console<\/span>.<span>log<\/span>(<span>`logged in as <\/span><span>${<\/span><span>client<\/span>.<span>user<\/span>.<span>tag<\/span><span>}<\/span><span>`<\/span>);&#13;\n});&#13;\n&#13;\n<span>\/\/Listen to new messages on the server&#13;\n<\/span><span>client<\/span>.<span>on<\/span>(<span>\"message\"<\/span>, <span>async<\/span> (<span>message<\/span>) =&gt; {&#13;\n  <span>if<\/span> (<span>message<\/span>.<span>content<\/span><span>===<\/span><span>\"ping\"<\/span>) {&#13;\n    <span>message<\/span>.<span>reply<\/span>(<span>\"pong\"<\/span>);&#13;\n  }&#13;\n});&#13;\n&#13;\n<span>\/\/Login to the server using bot token&#13;\n<\/span><span>client<\/span>.<span>login<\/span>(<span>process<\/span>.<span>env<\/span>.<span>TOKEN<\/span>);<\/code><\/pre>\n<p>There are a few important things happening in this code. First, we import the discord.js module and create a new Client object, which represents the Discord bot in this scenario. The<span>\u00a0<\/span><code>client.login<\/code><span>\u00a0<\/span>method then allows the bot to log in to Discord using the token we added to the .env file. The dotenv module takes care of adding it as an environment variable to the process.<\/p>\n<p>Our bot listens to two Discord events: ready and message. The ready event is triggered when the bot is ready to be used. And the message event is triggered every time a user sends a message to a channel. Here, we set up the bot to reply to every message that sends \u201cping\u201d with a \u201cpong.\u201d<\/p>\n<p>When we run this Node script using the<span>\u00a0<\/span><code>node index<\/code><span>\u00a0<\/span>command, the bot, which has stayed offline so far, goes online and starts working.<\/p>\n<figure class=\"post-image post-mediaBleed aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1360727 js-lazy\" alt=\"See your bot online\" width=\"504\" height=\"348\" sizes=\"auto, (max-width: 504px) 100vw, 504px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord9.jpg\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord9.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord9-280x193.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord9-391x270.jpg 391w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord9-196x135.jpg 196w\"\/><figcaption><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/thenextweb.com\/news\/#\" data-url=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Feditorial.thenextweb.com%2Ftech%2F2021%2F07%2F15%2Fbuild-discord-bot-in-under-60-minutes-syndication%2F&amp;via=thenextweb&amp;related=thenextweb&amp;text=Check out this picture on: See your bot online.\" data-title=\"Share See your bot online. on Twitter\" data-width=\"685\" data-height=\"500\" class=\"post-image-share popitup\" title=\"Share See your bot online. on Twitter\"><i class=\"icon icon--inline icon--twitter--dark\"\/><\/a>See your bot online.<\/figcaption><noscript><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1360727\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord9.jpg\" alt=\"See your bot online\" width=\"504\" height=\"348\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord9.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord9-280x193.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord9-391x270.jpg 391w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord9-196x135.jpg 196w\"\/><\/noscript><\/figure>\n<p><span>You can send a ping message to a channel and test if it\u2019s working correctly.<\/span><\/p>\n<figure class=\"post-image post-mediaBleed aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360728 js-lazy\" alt=\"Test your basic bot\" width=\"700\" height=\"135\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord10.jpg\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord10.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord10-280x54.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord10-540x104.jpg 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord10-270x52.jpg 270w\"\/><figcaption><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/thenextweb.com\/news\/#\" data-url=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Feditorial.thenextweb.com%2Ftech%2F2021%2F07%2F15%2Fbuild-discord-bot-in-under-60-minutes-syndication%2F&amp;via=thenextweb&amp;related=thenextweb&amp;text=Check out this picture on: Test your basic bot.\" data-title=\"Share Test your basic bot. on Twitter\" data-width=\"685\" data-height=\"500\" class=\"post-image-share popitup\" title=\"Share Test your basic bot. on Twitter\"><i class=\"icon icon--inline icon--twitter--dark\"\/><\/a>Test your basic bot.<\/figcaption><noscript><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360728\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord10.jpg\" alt=\"Test your basic bot\" width=\"700\" height=\"135\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord10.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord10-280x54.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord10-540x104.jpg 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord10-270x52.jpg 270w\"\/><\/noscript><\/figure>\n<h2 id=\"reply-to-a-user-with-a-random-dad-joke-at-user-request\"><span class=\"ez-toc-section\" id=\"Reply_to_a_user_with_a_random_Dad_joke\"><\/span>Reply to a user with a random Dad joke<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Finally, we\u2019ve come to the fun part of the project. Here, we will set our bot to reply to any user who directly mentions it with a random dad joke. For this, we are using this API:<span>\u00a0<\/span><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/icanhazdadjoke.com\/api\">icanhazdadjoke.com<\/a>. It has a great collection of funny (and awkward) dad jokes we can retrieve for free.<\/p>\n<p>The basic logic of this implementation goes like this. When a user mentions our bot, it sends a request to the dad joke API using axios and retrieves a random dad joke. Then it replies to the user with the joke. Quite simple.<\/p>\n<p>One thing to note here is that we need to set up the Accept Headers of the GET request to application\/json to retrieve the results from the API in JSON format.<\/p>\n<div class=\"highlight\">\n<pre><code class=\"language-javascript\"><span>require<\/span>(<span>\"dotenv\"<\/span>).<span>config<\/span>();&#13;\n<span>const<\/span><span>axios<\/span><span>=<\/span><span>require<\/span>(<span>\"axios\"<\/span>);&#13;\n<span>const<\/span><span>Discord<\/span><span>=<\/span><span>require<\/span>(<span>\"discord.js\"<\/span>);&#13;\n<span>const<\/span><span>client<\/span><span>=<\/span><span>new<\/span><span>Discord<\/span>.<span>Client<\/span>();&#13;\n&#13;\n<span>const<\/span><span>dadJokeURL<\/span><span>=<\/span><span>\"https:\/\/icanhazdadjoke.com\"<\/span>;&#13;\n<span>const<\/span><span>headers<\/span><span>=<\/span> { <span>\"Accept\"<\/span><span>:<\/span><span>\"application\/json\"<\/span> };&#13;\n&#13;\n<span>async<\/span><span>function<\/span><span>getRandomDadJoke<\/span>() {&#13;\n  <span>const<\/span><span>response<\/span><span>=<\/span><span>await<\/span><span>axios<\/span>.<span>get<\/span>(<span>dadJokeURL<\/span>, { <span>headers<\/span><span>:<\/span><span>headers<\/span> });&#13;\n  <span>return<\/span><span>response<\/span>.<span>data<\/span>;&#13;\n}&#13;\n&#13;\n<span>\/\/Listen to the event that signals bot is ready to start working&#13;\n<\/span><span>client<\/span>.<span>on<\/span>(<span>\"ready\"<\/span>, () =&gt; {&#13;\n  <span>console<\/span>.<span>log<\/span>(<span>`logged in as <\/span><span>${<\/span><span>client<\/span>.<span>user<\/span>.<span>tag<\/span><span>}<\/span><span>`<\/span>);&#13;\n});&#13;\n&#13;\n<span>\/\/Listen to new messages on the server&#13;\n<\/span><span>client<\/span>.<span>on<\/span>(<span>\"message\"<\/span>, <span>async<\/span> (<span>message<\/span>) =&gt; {&#13;\n    <span>\/\/\"Ignore the message if the bot authored it\"&#13;\n<\/span><span>if<\/span> (<span>message<\/span>.<span>author<\/span>.<span>bot<\/span>) <span>return<\/span>;&#13;\n&#13;\n    <span>\/\/If the doesn't specifically mention the bot, return&#13;\n<\/span><span>if<\/span> (<span>text<\/span>.<span>includes<\/span>(<span>\"@here\"<\/span>) <span>||<\/span><span>text<\/span>.<span>includes<\/span>(<span>\"@everyone\"<\/span>)) <span>return<\/span>;&#13;\n&#13;\n    <span>\/\/Return if the message doesn't mention the bot&#13;\n<\/span><span>if<\/span> (<span>!<\/span><span>message<\/span>.<span>mentions<\/span>.<span>has<\/span>(<span>client<\/span>.<span>user<\/span>.<span>id<\/span>)) <span>return<\/span>;&#13;\n&#13;\n    <span>try<\/span> {  &#13;\n        <span>\/\/Reply with a random joke&#13;\n<\/span><span>const<\/span><span>result<\/span><span>=<\/span><span>await<\/span><span>getRandomDadJoke<\/span>();&#13;\n        <span>message<\/span>.<span>reply<\/span>(<span>result<\/span>.<span>joke<\/span>);&#13;\n    }&#13;\n    <span>catch<\/span> (<span>error<\/span>) {&#13;\n      <span>message<\/span>.<span>reply<\/span>(<span>\"Sorry, an error occured\"<\/span>);&#13;\n    }&#13;\n});&#13;\n&#13;\n<span>\/\/Login to the server using bot token&#13;\n<\/span><span>client<\/span>.<span>login<\/span>(<span>process<\/span>.<span>env<\/span>.<span>TOKEN<\/span>);&#13;\n<\/code><\/pre>\n<\/div>\n<p>The<span>\u00a0<\/span><code>getRandomDadJoke<\/code><span>\u00a0<\/span>method sends the axios request and returns the retrieved data with the random joke. In the message handler, the bot listens to the message events and determines which messages it should reply to. It eliminates three types of messages.<\/p>\n<ul>\n<li>Messages authored by the bot itself.<\/li>\n<li>Messages that mention everyone on the server, not just the bot.<\/li>\n<li>Messages that don\u2019t mention the bot.<\/li>\n<\/ul>\n<p>If a user directly mentions the bot, it replies with a random joke retrieved using the<span>\u00a0<\/span><code>getRandomDadJoke<\/code><span>\u00a0<\/span>method.<\/p>\n<p>You can stop and start the Node script to get the modified bot running on the server.<\/p>\n<figure class=\"post-image post-mediaBleed aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360730 js-lazy\" alt=\"Now the bot can reply information from the API\" width=\"700\" height=\"133\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord11.jpg\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord11.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord11-280x53.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord11-540x103.jpg 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord11-270x51.jpg 270w\"\/><figcaption><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/thenextweb.com\/news\/#\" data-url=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Feditorial.thenextweb.com%2Ftech%2F2021%2F07%2F15%2Fbuild-discord-bot-in-under-60-minutes-syndication%2F&amp;via=thenextweb&amp;related=thenextweb&amp;text=Check out this picture on: Now the bot can reply information from the API.\" data-title=\"Share Now the bot can reply information from the API. on Twitter\" data-width=\"685\" data-height=\"500\" class=\"post-image-share popitup\" title=\"Share Now the bot can reply information from the API. on Twitter\"><i class=\"icon icon--inline icon--twitter--dark\"\/><\/a>Now the bot can reply information from the API.<\/figcaption><noscript><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360730\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord11.jpg\" alt=\"Now the bot can reply information from the API\" width=\"700\" height=\"133\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord11.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord11-280x53.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord11-540x103.jpg 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord11-270x51.jpg 270w\"\/><\/noscript><\/figure>\n<h2 id=\"search-for-a-dad-joke-with-a-user-provided-search-term\"><span class=\"ez-toc-section\" id=\"Search_for_a_Dad_joke_with_a_user-provided_search_term\"><\/span>Search for a Dad joke with a user-provided search term<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>This implementation is not too different from the last one. But here, users can submit a search term to get a dad joke on a specific topic.<\/p>\n<p>To do this, we must add a new function called<span>\u00a0<\/span><code>searchDadJokes<\/code><span>\u00a0<\/span>which sends the request to the<span>\u00a0<\/span><code>\/search<\/code><span>\u00a0<\/span>API endpoint with the search term as a query parameter. We also set the<span>\u00a0<\/span><code>limit=1<\/code><span>\u00a0<\/span>to retrieve only one joke on a given subject.<\/p>\n<div class=\"highlight\">\n<pre><code class=\"language-javascript\"><span>async<\/span><span>function<\/span><span>searchDadJokes<\/span>(<span>term<\/span>) {&#13;\n    <span>const<\/span><span>params<\/span><span>=<\/span> { <span>term<\/span><span>:<\/span><span>term<\/span>, <span>limit<\/span><span>:<\/span><span>1<\/span> }&#13;\n    <span>const<\/span><span>response<\/span><span>=<\/span><span>await<\/span><span>axios<\/span>.<span>get<\/span>(<span>`<\/span><span>${<\/span><span>dadJokeURL<\/span><span>}<\/span><span>\/search`<\/span>, { <span>params<\/span><span>:<\/span><span>params<\/span>, <span>headers<\/span><span>:<\/span><span>headers<\/span> });&#13;\n    <span>return<\/span><span>response<\/span>.<span>data<\/span>.<span>results<\/span>[<span>0<\/span>];&#13;\n}&#13;\n<\/code><\/pre>\n<\/div>\n<p>Then, we have to modify the message event handler to consider the case the user submits a search term. Here\u2019s how we do it.<\/p>\n<div class=\"highlight\">\n<pre><code class=\"language-javascript\"><span>\/\/Listen to new messages on the server&#13;\n<\/span><span>client<\/span>.<span>on<\/span>(<span>\"message\"<\/span>, <span>async<\/span> (<span>message<\/span>) =&gt; {&#13;\n&#13;\n    <span>\/\/\"Ignore the message if the bot authored it\"&#13;\n<\/span><span>if<\/span> (<span>message<\/span>.<span>author<\/span>.<span>bot<\/span>) <span>return<\/span>;&#13;\n&#13;\n    <span>const<\/span><span>text<\/span><span>=<\/span><span>message<\/span>.<span>content<\/span>.<span>toLowerCase<\/span>();&#13;\n&#13;\n    <span>\/\/If the doesn't specifically mention, bot return&#13;\n<\/span><span>if<\/span> (<span>text<\/span>.<span>includes<\/span>(<span>\"@here\"<\/span>) <span>||<\/span><span>text<\/span>.<span>includes<\/span>(<span>\"@everyone\"<\/span>)) <span>return<\/span>;&#13;\n&#13;\n    <span>\/\/Return if the message doesn't mention the bot&#13;\n<\/span><span>if<\/span> (<span>!<\/span><span>message<\/span>.<span>mentions<\/span>.<span>has<\/span>(<span>client<\/span>.<span>user<\/span>.<span>id<\/span>)) <span>return<\/span>;&#13;\n&#13;\n    <span>let<\/span><span>result<\/span>;&#13;\n    <span>try<\/span> {&#13;\n        <span>const<\/span><span>term<\/span><span>=<\/span><span>text<\/span>.<span>replace<\/span>(<span>\/&lt;@!d+&gt;\/<\/span>, <span>\"\"<\/span>).<span>trim<\/span>();&#13;\n&#13;\n        <span>\/\/If there is a search term&#13;\n<\/span><span>if<\/span> (<span>term<\/span><span>!==<\/span><span>\"\"<\/span>) {&#13;\n            <span>\/\/Search a joke containing the term&#13;\n<\/span><span>result<\/span><span>=<\/span><span>await<\/span><span>searchDadJokes<\/span>(<span>term<\/span>);&#13;\n            <span>if<\/span> (<span>!<\/span><span>result<\/span>) {&#13;\n                <span>message<\/span>.<span>reply<\/span>(<span>`Sorry, got no dad jokes about <\/span><span>${<\/span><span>term<\/span><span>}<\/span><span>. But how about a random dad joke?`<\/span>);&#13;\n            }&#13;\n        }&#13;\n&#13;\n        <span>\/\/Reply with a random joke&#13;\n<\/span><span>if<\/span> (<span>!<\/span><span>result<\/span>) {&#13;\n            <span>result<\/span><span>=<\/span><span>await<\/span><span>getRandomDadJoke<\/span>();&#13;\n        }&#13;\n&#13;\n        <span>message<\/span>.<span>reply<\/span>(<span>result<\/span>.<span>joke<\/span>);&#13;\n    }&#13;\n    <span>catch<\/span> (<span>error<\/span>) {&#13;\n        <span>message<\/span>.<span>reply<\/span>(<span>\"Sorry, an error occured\"<\/span>)&#13;\n    }&#13;\n});<\/code><\/pre>\n<p>To check if a user has submitted a search term, we need to remove the bot\u2019s ID from the text. It\u2019s added to the text when the user mentions the bot. A mentioned ID appears in the text in the following format.<\/p>\n<\/div>\n<p>We can detect IDs in text using the regex pattern<span>\u00a0<\/span><code>&lt;@!d+&gt;<\/code><span>\u00a0<\/span>and replace it with an empty string. After trimming the modified text, the bot can retrieve the search term that was submitted. Then, the bot uses the<span>\u00a0<\/span><code>searchDadJokes<\/code><span>\u00a0<\/span>method to find a relevant joke.<\/p>\n<p>If the API database doesn\u2019t have a joke on a particular topic, the bot replies to the user explaining the situation along with a random joke. If the user doesn\u2019t submit a search term, it responds with a random joke by default.<\/p>\n<p>The rest of the code stays similar to the last scenario. So, we can now run and test this new feature of our bot.<\/p>\n<p>When there\u2019s is a joke related to the search term:<\/p>\n<figure class=\"post-image post-mediaBleed aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360733 js-lazy\" alt=\"Send jokes related to a query\" width=\"700\" height=\"136\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord12.jpg\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord12.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord12-280x54.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord12-540x105.jpg 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord12-270x52.jpg 270w\"\/><figcaption><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/thenextweb.com\/news\/#\" data-url=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Feditorial.thenextweb.com%2Ftech%2F2021%2F07%2F15%2Fbuild-discord-bot-in-under-60-minutes-syndication%2F&amp;via=thenextweb&amp;related=thenextweb&amp;text=Check out this picture on: Send jokes related to a query.\" data-title=\"Share Send jokes related to a query. on Twitter\" data-width=\"685\" data-height=\"500\" class=\"post-image-share popitup\" title=\"Share Send jokes related to a query. on Twitter\"><i class=\"icon icon--inline icon--twitter--dark\"\/><\/a>Send jokes related to a query.<\/figcaption><noscript><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360733\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord12.jpg\" alt=\"Send jokes related to a query\" width=\"700\" height=\"136\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord12.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord12-280x54.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord12-540x105.jpg 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord12-270x52.jpg 270w\"\/><\/noscript><\/figure>\n<p><span>When there\u2019s no joke on the submitted term:<\/span><\/p>\n<figure class=\"post-image post-mediaBleed aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360734 js-lazy\" alt=\"Use a fallback random joke when nothing was found\" width=\"700\" height=\"167\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord13.png\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord13.png 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord13-280x67.png 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord13-540x129.png 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord13-270x64.png 270w\"\/><figcaption><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/thenextweb.com\/news\/#\" data-url=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Feditorial.thenextweb.com%2Ftech%2F2021%2F07%2F15%2Fbuild-discord-bot-in-under-60-minutes-syndication%2F&amp;via=thenextweb&amp;related=thenextweb&amp;text=Check out this picture on: Use a fallback random joke when nothing was found.\" data-title=\"Share Use a fallback random joke when nothing was found. on Twitter\" data-width=\"685\" data-height=\"500\" class=\"post-image-share popitup\" title=\"Share Use a fallback random joke when nothing was found. on Twitter\"><i class=\"icon icon--inline icon--twitter--dark\"\/><\/a>Use a fallback random joke when nothing was found.<\/figcaption><noscript><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360734\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord13.png\" alt=\"Use a fallback random joke when nothing was found\" width=\"700\" height=\"167\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord13.png 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord13-280x67.png 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord13-540x129.png 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord13-270x64.png 270w\"\/><\/noscript><\/figure>\n<h2 id=\"welcome-new-members\"><span class=\"ez-toc-section\" id=\"Welcome_new_members\"><\/span>Welcome new members<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>We can set up our bot to welcome every new user who joins the Discord server. When the bot detects a new \u201cguildMemberAdd\u201d event, which signals a new user has joined, it sends a message to the \u201c<a href=\"https:\/\/buradabiliyorum.com\/en\/category\/general\/\" data-internallinksmanager029f6b8e52c=\"3\" title=\"General\" target=\"_blank\" rel=\"noopener\">general<\/a>\u201d channel welcoming the new user.<\/p>\n<div class=\"highlight\">\n<pre><code class=\"language-javascript\"><span>\/\/Listen to new member joining event&#13;\n<\/span><span>client<\/span>.<span>on<\/span>(<span>\"guildMemberAdd\"<\/span>, <span>member<\/span> =&gt; {&#13;\n<span>\/\/Find the general channel in the user's channel list to send the welcome message&#13;\n<\/span><span>const<\/span><span>channel<\/span><span>=<\/span><span>member<\/span>.<span>guild<\/span>.<span>channels<\/span>.<span>cache<\/span>.<span>find<\/span>(<span>ch<\/span> =&gt; <span>ch<\/span>.<span>name<\/span><span>===<\/span><span>\"general\"<\/span>);&#13;\n&#13;\n    <span>\/\/If the channel is not in the server, exit&#13;\n<\/span><span>if<\/span> (<span>!<\/span><span>channel<\/span>) <span>return<\/span>;&#13;\n&#13;\n    <span>channel<\/span>.<span>send<\/span>(<span>`Welcome, <\/span><span>${<\/span><span>member<\/span><span>}<\/span><span>! I'm at your service if you want to hear dad jokes`<\/span>);&#13;\n});&#13;\n<\/code><\/pre>\n<\/div>\n<p>Here\u2019s how this feature works on the server when a new user joins:<\/p>\n<figure class=\"post-image post-mediaBleed aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360735 js-lazy\" alt=\"Bot welcomes user\" width=\"700\" height=\"127\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord14.jpg\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord14.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord14-280x51.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord14-540x98.jpg 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord14-270x49.jpg 270w\"\/><figcaption><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/thenextweb.com\/news\/#\" data-url=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Feditorial.thenextweb.com%2Ftech%2F2021%2F07%2F15%2Fbuild-discord-bot-in-under-60-minutes-syndication%2F&amp;via=thenextweb&amp;related=thenextweb&amp;text=Check out this picture on: Bot welcomes user.\" data-title=\"Share Bot welcomes user. on Twitter\" data-width=\"685\" data-height=\"500\" class=\"post-image-share popitup\" title=\"Share Bot welcomes user. on Twitter\"><i class=\"icon icon--inline icon--twitter--dark\"\/><\/a>Bot welcomes user.<\/figcaption><noscript><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360735\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord14.jpg\" alt=\"Bot welcomes user\" width=\"700\" height=\"127\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord14.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord14-280x51.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord14-540x98.jpg 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord14-270x49.jpg 270w\"\/><\/noscript><\/figure>\n<p><span>With that, we have completed the development of our Discord bot. You can now add the bot to any server where you have \u201cManage Server\u201d permission and have fun reading random dad jokes.<\/span><\/p>\n<h2 id=\"deploying-the-bot-to-heroku\"><span class=\"ez-toc-section\" id=\"Deploying_the_bot_to_Heroku\"><\/span>Deploying the bot to Heroku<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Running the bot locally on your machine is not ideal if you want to keep it working 24\/7. So, to make it continuously available, we will deploy the bot to the<span>\u00a0<\/span><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/heroku.com\/\">Heroku<\/a><span>\u00a0<\/span>cloud.<\/p>\n<p>First, we should create a<span>\u00a0<\/span><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/devcenter.heroku.com\/articles\/procfile\">Procfile<\/a><span>\u00a0<\/span>in our project folder specifying the commands that Heroku should execute at the application start. We add a new worker process with npm node index.js as starting command to the Procfile.<\/p>\n<div class=\"highlight\">\n<pre><code class=\"language-text\">\/\/Procfile&#13;\n&#13;\nworker: node index.js&#13;\n<\/code><\/pre>\n<\/div>\n<p>Next, we need to initialize the project as a git repository and push it to GitHub. We can connect the GitHub repo to Heroku which will deploy the bot. We recommend adding the node_modules folder and .env file to a .gitignore file before pushing the project to GitHub.<\/p>\n<p>Once you log in to Heroku (create an account if you don\u2019t have one), you\u2019ll be redirected to the Heroku dashboard. Here you can create a new application by clicking on the \u201cNew\u201d button.<\/p>\n<figure class=\"post-image post-mediaBleed aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360736 js-lazy\" alt=\"Heroku new app menu\" width=\"700\" height=\"64\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord15.jpg\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord15.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord15-280x26.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord15-540x49.jpg 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord15-270x25.jpg 270w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord15-687x64.jpg 687w\"\/><figcaption><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/thenextweb.com\/news\/#\" data-url=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Feditorial.thenextweb.com%2Ftech%2F2021%2F07%2F15%2Fbuild-discord-bot-in-under-60-minutes-syndication%2F&amp;via=thenextweb&amp;related=thenextweb&amp;text=Check out this picture on: Heroku new app menu.\" data-title=\"Share Heroku new app menu. on Twitter\" data-width=\"685\" data-height=\"500\" class=\"post-image-share popitup\" title=\"Share Heroku new app menu. on Twitter\"><i class=\"icon icon--inline icon--twitter--dark\"\/><\/a>Heroku new app menu.<\/figcaption><noscript><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360736\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord15.jpg\" alt=\"Heroku new app menu\" width=\"700\" height=\"64\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord15.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord15-280x26.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord15-540x49.jpg 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord15-270x25.jpg 270w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord15-687x64.jpg 687w\"\/><\/noscript><\/figure>\n<p><span>Choose the \u201cCreate new app\u201d option, give your application a name, and confirm the app creation.<\/span><\/p>\n<figure class=\"post-image post-mediaBleed aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360738 js-lazy\" alt=\"Heroku new app form\" width=\"700\" height=\"364\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord16.jpg\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord16.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord16-280x146.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord16-519x270.jpg 519w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord16-260x135.jpg 260w\"\/><figcaption><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/thenextweb.com\/news\/#\" data-url=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Feditorial.thenextweb.com%2Ftech%2F2021%2F07%2F15%2Fbuild-discord-bot-in-under-60-minutes-syndication%2F&amp;via=thenextweb&amp;related=thenextweb&amp;text=Check out this picture on: Heroku new app form.\" data-title=\"Share Heroku new app form. on Twitter\" data-width=\"685\" data-height=\"500\" class=\"post-image-share popitup\" title=\"Share Heroku new app form. on Twitter\"><i class=\"icon icon--inline icon--twitter--dark\"\/><\/a>Heroku new app form.<\/figcaption><noscript><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360738\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord16.jpg\" alt=\"Heroku new app form\" width=\"700\" height=\"364\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord16.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord16-280x146.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord16-519x270.jpg 519w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord16-260x135.jpg 260w\"\/><\/noscript><\/figure>\n<p><span>The new application will be listed on your Heroku dashboard. Select the application and go to the deploy tab, where you\u2019ll find the option to connect your GitHub account. After connecting the account, search for the app repository and click on \u201cConnect.\u201d<\/span><\/p>\n<figure class=\"post-image post-mediaBleed aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1360739 size-full js-lazy\" alt=\"Connect Heroku app with git repository\" width=\"700\" height=\"188\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord17.jpg\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord17.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord17-280x75.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord17-540x145.jpg 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord17-270x73.jpg 270w\"\/><figcaption><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/thenextweb.com\/news\/#\" data-url=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Feditorial.thenextweb.com%2Ftech%2F2021%2F07%2F15%2Fbuild-discord-bot-in-under-60-minutes-syndication%2F&amp;via=thenextweb&amp;related=thenextweb&amp;text=Check out this picture on: Connect Heroku app with git repository.\" data-title=\"Share Connect Heroku app with git repository. on Twitter\" data-width=\"685\" data-height=\"500\" class=\"post-image-share popitup\" title=\"Share Connect Heroku app with git repository. on Twitter\"><i class=\"icon icon--inline icon--twitter--dark\"\/><\/a>Connect Heroku app with git repository.<\/figcaption><noscript><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1360739 size-full\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord17.jpg\" alt=\"Connect Heroku app with git repository\" width=\"700\" height=\"188\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord17.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord17-280x75.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord17-540x145.jpg 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord17-270x73.jpg 270w\"\/><\/noscript><\/figure>\n<p><span>Heroku will now automatically deploy your app via the GitHub repository. You can enable automatic deployment to deploy the repo every time you push new changes.<\/span><\/p>\n<figure class=\"post-image post-mediaBleed aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360740 js-lazy\" alt=\"Set up automatic deployments on Heroku\" width=\"700\" height=\"170\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord18.jpg\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord18.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord18-280x68.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord18-540x131.jpg 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord18-270x66.jpg 270w\"\/><figcaption><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/thenextweb.com\/news\/#\" data-url=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Feditorial.thenextweb.com%2Ftech%2F2021%2F07%2F15%2Fbuild-discord-bot-in-under-60-minutes-syndication%2F&amp;via=thenextweb&amp;related=thenextweb&amp;text=Check out this picture on: Set up automatic deployments on Heroku.\" data-title=\"Share Set up automatic deployments on Heroku. on Twitter\" data-width=\"685\" data-height=\"500\" class=\"post-image-share popitup\" title=\"Share Set up automatic deployments on Heroku. on Twitter\"><i class=\"icon icon--inline icon--twitter--dark\"\/><\/a>Set up automatic deployments on Heroku.<\/figcaption><noscript><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360740\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord18.jpg\" alt=\"Set up automatic deployments on Heroku\" width=\"700\" height=\"170\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord18.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord18-280x68.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord18-540x131.jpg 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord18-270x66.jpg 270w\"\/><\/noscript><\/figure>\n<p><span>Next, go to the Settings tab and add the bot token to the \u201cconfig vars\u201d section. This adds the token to the env variables of the process. If you want, you can remove the dotenv configuration in the initial application code.<\/span><\/p>\n<figure class=\"post-image post-mediaBleed aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360745 js-lazy\" alt=\"Add env variables\" width=\"700\" height=\"129\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord19.jpg\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord19.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord19-280x52.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord19-540x100.jpg 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord19-270x50.jpg 270w\"\/><figcaption><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/thenextweb.com\/news\/#\" data-url=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Feditorial.thenextweb.com%2Ftech%2F2021%2F07%2F15%2Fbuild-discord-bot-in-under-60-minutes-syndication%2F&amp;via=thenextweb&amp;related=thenextweb&amp;text=Check out this picture on: Add env variables\" data-title=\"Share Add env variables on Twitter\" data-width=\"685\" data-height=\"500\" class=\"post-image-share popitup\" title=\"Share Add env variables on Twitter\"><i class=\"icon icon--inline icon--twitter--dark\"\/><\/a>Add env variables<\/figcaption><noscript><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360745\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord19.jpg\" alt=\"Add env variables\" width=\"700\" height=\"129\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord19.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord19-280x52.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord19-540x100.jpg 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord19-270x50.jpg 270w\"\/><\/noscript><\/figure>\n<p><span>We have to make one more change to complete the deployment. For this, go to the Resources tab of the application. Currently, the \u201cweb\u201d option is turned on in the free dynos section while the \u201cworker\u201d is turned off. Instead, you should turn on \u201cworker\u201d and turn off \u201cweb\u201d to prevent the app from crashing due to a\u00a0<\/span><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/help.heroku.com\/W5ETWBQB\/why-is-my-app-crashing-with-an-r10-error\">60-second timeout error<\/a><span>.<\/span><\/p>\n<figure class=\"post-image post-mediaBleed aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360746 js-lazy\" alt=\"Set up app as worker\" width=\"700\" height=\"139\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord20.jpg\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord20.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord20-280x56.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord20-540x107.jpg 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord20-270x54.jpg 270w\"\/><figcaption><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/thenextweb.com\/news\/#\" data-url=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Feditorial.thenextweb.com%2Ftech%2F2021%2F07%2F15%2Fbuild-discord-bot-in-under-60-minutes-syndication%2F&amp;via=thenextweb&amp;related=thenextweb&amp;text=Check out this picture on: Set up app as worker.\" data-title=\"Share Set up app as worker. on Twitter\" data-width=\"685\" data-height=\"500\" class=\"post-image-share popitup\" title=\"Share Set up app as worker. on Twitter\"><i class=\"icon icon--inline icon--twitter--dark\"\/><\/a>Set up app as worker.<\/figcaption><noscript><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1360746\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord20.jpg\" alt=\"Set up app as worker\" width=\"700\" height=\"139\" srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord20.jpg 700w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord20-280x56.jpg 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord20-540x107.jpg 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discord20-270x54.jpg 270w\"\/><\/noscript><\/figure>\n<p><span>With that, the app deployment is complete. Now, our Discord bot can run 24\/7 on a server and provide an endless supply of dad jokes.<\/span><\/p>\n<h2 id=\"summary\"><span class=\"ez-toc-section\" id=\"Summary\"><\/span>Summary<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Discord API is a powerful tool that allows developers to build various applications for Discord, including bots. The Node-based discord.js package makes it even easier for us to take advantage of this tool.<\/p>\n<p>Today, we created a simple bot that could do several automated tasks, including messaging channels, welcoming new members, and retrieving content from a remote API. It\u2019s a fun experience anyone can try that would prepare you for building more serious, complex bots. I hope you\u2019ll enjoy experimenting with the Discord API with what we learned today.<\/p>\n<p><i><span>This <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/livecodestream.dev\/post\/build-your-first-discord-bot-in-less-than-an-hour\/\">article<\/a>\u00a0<\/span><\/i><i><span>was originally published on\u00a0<\/span><\/i><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/livecodestream.dev\/\"><i><span>Live Code Stream<\/span><\/i><\/a><i><span>\u00a0by\u00a0Anjalee Sudasinghe<\/span><\/i><i><span>.<\/span><\/i><\/p>\n<figure class=\"\"\/><\/div>\n<p><script async src=\"\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script><\/p>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong>\n<\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/thenextweb.com\/news\/build-discord-bot-in-under-60-minutes-syndication\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#Here\u2019s how to build an interactive Discord bot in under 60 minutes&#8221; Discord\u00a0is a instant messaging and digital distribution platform designed for creating communities. With over 100 million users, the service allows you to communicate with voice calls, video calls, text messaging, media and files in private chats, or ,as part of communities called \u201cservers\u201d&#8230;.<\/p>\n","protected":false},"author":1,"featured_media":299889,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/img-cdn.tnwcdn.com\/image\/tnw?filter_last=1&fit=1280,640&url=https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2021\/07\/Discordhed.jpg&signature=fe31c8829d2e125837e71cacd0d26877","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-299888","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/299888","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=299888"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/299888\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/299889"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=299888"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=299888"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=299888"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}