Discord chatbot 🤖 with IBM Watson 
Tags: javascript, ibmwatson, cloud
Published: 2020-11-09 02:40:06

>*Not really that I was going to create a custom chatbot for my son's Discord friends as they play a new season of Fortnite* 😄, *but more likely to enhance it with AI services based on IBM Watson and give a head start with Watson Assistant - a comprehensive chatbot framework with built-in machine learning capabilities.*

>*And this is how it all started...*

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/b2ozvveycbo6nsje7ofk.jpeg)

## Let’s learn more about: 
### Discord
Discord is an American VoIP, instant messaging, and digital distribution platform designed for creating communities used by over a hundred million people to hang out and talk with their friends and communities.

Since its launch in 2015, [Discord](https://discord.com/) has been growing explosively – with over 14 million active daily users, which is more than [Slack](https://slack.com/) which has just 10 million daily active users. In May 2019, Discord reached over 250 million users.

### Chatbot 
A chatbot is a software application that simulates human conversation through voice commands or text chats or both. Chatbot, short for chatterbot, is an Artificial Intelligence (AI) feature that can be embedded and used through any major messaging applications.

### IBM Watson

Use IBM [Watson Assistant](https://www.ibm.com/cloud/watson-assistant) to build your own branded live chatbot into any device, application, or channel. 

You will use free of charge AI-based chatbot engine with Watson Assistant from IBM Cloud.

## Now, let’s get started with:

-How to add a chatbot to Discord using IBM Watson
-Intro to IBM Watson Assistant
-Deploying the chatbot in IBM Cloud 

###STEP 1. Connect to Discord service

Simply log in to your Discord account, or create a new one, and navigate to https://discordapp.com/developers/applications/

After making your new Discord server add the bot there:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/g757hqaeccv74q65fycf.jpeg)

Follow the next few steps to add the bot to your server, this is the URL to follow and add the bot:

https://discord.com/oauth2/authorize?client_id=CLIENT_ID&scope=bot

You can find and copy CLIENT-ID in the General Information tab: 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/5l112pwd074b1g56r3x5.jpeg)


The following step is to click Authorize:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/isxcjm4917npk9kudinj.jpeg)

After you click Authorize the bot should be in the list of the users:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/6qmdzfbgu3p51tf7l95u.jpeg)

###STEP 2. Getting the Ping-Pong BOT in Node.js, the Discord Node JavaScript library

### About Node.js
[Node.js](https://nodejs.org/en/) allows you to run JavaScript on the server. It's an open-source server environment and one of the most popular technologies nowadays to build scalable and efficient REST API's. Essentially, Node.js is a server-side runtime environment that allows us to execute JS outside the browser's domain. 
Node.js popularity around the world is constantly growing. It’s no wonder that over 177,393 websites (some of them being the BIGGEST players on the market) already put Node.js on their backend, such as:

- [Netflix](https://www.netflix.com/), the world's leading Internet television network is one of those top companies that trusted its servers to Node.js

- [Uber](https://www.uber.com/) has built its massive matching system on Node.js

- [PayPal](https://www.paypal.com/), one of the largest fintech leaders, has also trusted their back-end development to Node.js

- [LinkedIn](https://www.linkedin.com/), the world’s biggest professional social network, too, shifted its server-side code entirely to Node.js

- [Ebay](https://www.ebay.com/), a multinational e-commerce company

### Let's start with: 
Setting Up npm (Node Package Manager) and before we continue, let's make sure your environment is all set to work with npm that is automatically installed along with Node.js. To confirm you have node installed, enter the following into your command line:
node -v

If a version appears, you have Node.js. If, by chance, you do not have Node.js installed, you can use the Node Version Manager to install Node.js and keep it up to date.

The next step would be:

`mkdir mybot
cd mybot
npm install discord.js`

Create file index.js with the Example content (following the documentation here https://discord.js.org/#/

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/sosw2niqd4vbkcf8cc8h.jpeg)

Now you can replace the token with the token of your bot (It's NOT recommended to share the token 😄 and then run it with:

`node index.js`

If everything is connected correctly you have the bot online (`Logged in as ivana#7035!`):

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/r4lykdojqj77e9282zbq.jpeg)


###STEP 3. Chatbot AI features with IBM Watson Assistant
3. Adding the AI-powered chatbot backend

In order to create an AI-based chatbot engine, you will need the FREE Lite Account in IBM Cloud. Try Watson Assistant, just use this link to invoke IBM Cloud registration/signup/login page. 

>*I used this [URL](https://ibm.biz/Bd2CUaf), it gives to Speaker of Discord chatbot with IBM Watson on IBM Cloud Webinar Marek Sadowski some brownie points* 😄

You can simply go to Catalog and choose Watson Assistant:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/cbaxdcvh88yynjlj83ts.jpeg)

After you choose and create Watson Assistant from IBM Cloud Catalog, the AI-powered engine from IBM is ready to be tested.

For more details you should follow the [documentation]("https://developer.ibm.com/tutorials/create-your-first-assistant-powered-chatbot/") how to Create your first Assistant-powered chatbot:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/r2u78msi2kdvr2mfqjl4.jpeg)

##Next steps

>*To learn more check Discord chatbot with IBM Watson on IBM Cloud Webinar 3 part series [register here ](https://www.crowdcast.io/e/discord-chatbot-with-ibm-3/register).*


To connect with me please check my [Github](https://github.com/ivanadokic), [LinkedIn](https://www.linkedin.com/in/ivana-dokic/) or [Twitter](https://twitter.com/LloydPile). 

Thank you for reading!