In this article we are going to explain how to create a Discord Chatbot with Xenioo technology. But why should we create it? Well, because Discord is currently one of the fastest growing chat communities all over the world.
With 250 million users accounts and an average of 15 active million users daily it is becoming the platform of choice for a staggering amount of communities.
Xenioo just added full support for Discord as a brand new channel!
Designing our Discord Bot
The target functionality for our Discord chatbot would be:
- Wait for a trigger keyword from any user on a channel
- Search game information on an API service
- Present our results to the group
Thanks to Xenioo multi-channel designer, designing our Discord chatbot is exactly like designing any other chatbot so let’s start by the keyword trigger.
What we want is to catch any sentence starting with &search so that our chatbot is invoked only on specific requests by our users.
The above screenshot shows how this is easily done by simply using a Global Detection based on a Text Expression.
We could push it further and train our AI to detect free text search but a simple keyword is perfect for our current example.
When the bot detect the keyword, we want to extract only the part of the search that interests us. To do that we simply remove the &search keyword and trim spaces from the final text.
The last message we added is just a small test we can use to check that our user_search variable really contains only the text for our lookup.
Integrating with a gaming API service
Now that we have the search text for our user we need a gaming API service that can provide us with information. For our example we picked RAWG, one of the top players in this business.
After acquiring an API Key for their service we need to integrate the URL method in Xenioo by using the standard API Action in our design.
Our action will invoke the RAWG service submitting the user search and will store the resulting data into the search_results variable.
From there, using Xenioo Dynamic Parsing we can immediately check if we received any result.
As you can see in our variable check we can directly refer to JSON variables as they were properties of our search_results variable: the count field, contained in the json can be specified simply as search_results.count.
The same way we notify the user with zero results we want to make sure that search is sufficiently refined.
Let’s add add another Variable Switch Action. It will checks if there are too many games found.
If our search results are in an acceptable range we display a result card to our user with a nice screenshot and some additional details.
Again, here we use direct Dynamic Parsing to refer to the model entry at index 0 (zero) without using any code at all.
Discord does not support carousel cards but Xenioo will automatically translate the content to the next best thing: Discord Embedded Content.
A nice thing about Embedded Content is that it supports a nice view of multiple values that can be used to a good effect here and is fully supported by Xenioo.
Now that was quick! Our chatbot is ready and all we need to do now is publishing it on Discord.
Creating a Discord Chatbot
Creating a bot on Discord is a very simple process made of a few steps.
First of all we need, of course, a Discord account and with that login to the Discord Developers Portal. Once we’ve logged to our account we just need to create a new Application. Give it any name: it won’t be the name of the bot on Discord.
After you created the application, just click on the “Bot” menu option and create a new bot.
This time, give it a name you like and it will be the name that all users will see. Right below the bot name you’ll see the Token area: click on the copy button and go back to Xenioo.
On Xenioo, click on the publish button and the select discord. On the Auth Token field paste the token you just copied from the Discord bot page.
Since we’re on this page it would be a good idea to add a message filter for this bot.
Why? You can add your Discord bot on channels with hundreds of thousands of users and it wouldn’t be of any use to just parse every message: we can just get any message starting with a & (since our only command now is &search).
Save and click on publish. Your bot is online! Time to invite the bot to your channel.
Inviting the Discord chatbot
Your chatbot can live in any number of channels. Discord approach to bot is very interesting: you share an invite url for the bot that anyone can visit. As they visit the link they will see the option to add your chatbot to their server.
To build our invite link let’s go back to the Discord application page and select OAuth2 on the left menu. Scroll to the bottom in the scopes section click on “bot”.
An additional permissions area will open up. Select the basic permission for our bot following the ticks below:
Your invite link is now ready. Click on copy and share your awsome game searching Discord chatbot to the world!
To Sum Things Up…
We’ve just seen how easy it is to integrate Xenioo new Discord channel and create a stunning Discord chatbot with it.
You can find this chatbot template in the Xenioo Template page of your account. Don’t yet have a Xenioo account? Just create one for free here!
Do you have any question about this chatbot? Do you want to let us help on your awesome bot idea? Be sure to get in touch with the Xenioo team at email@example.com or leave a message on our Facebook Group.