Generic filters

How to create or add a Crypto Price bot to Discord server?

Written by The Guardian — June 2, 2022
Est. reading time: 8 min

Just started your new crypto server?

A price bot is a good feature to keep your community members' attention within the discord channel instead of focusing their attention on other charting websites.

In this tutorial, we will teach you exactly how you can set up your own Customised Price bot for your project even if it is not listed on Coingecko yet.

Before you install this crypto price bot, make sure you are clear on the following features:

This price bot only works on the following blockchains:

  • Ethereum Mainnet
  • Binance Smart Chain Mainnet
  • Polygon (Matic) Mainnet
  • Avalanche Mainnet
  • Fantom Mainnet
  • Cronos Mainnet

If you do not have a computer running 24/7, you will be required to use external hosting, firebase, to run your program which may incur some fees depending on your price update frequency and how many price bots you have.

For moderate usage, the monthly cost should be negligible in the cents or even free as long as you stay under the threshold.

We will be using Firebase for our Bot application which you will need to create an account and input your credit card details later.

We will also be using the Moralis API instead of the free CoinGecko API as your project may not be listed on CoinGecko yet.

Moralis API is free as well as long as you don't go overboard with the frequency that you request the new pricing.

The current setting of 1 minute per interval should be well under the 10million request per month for Moralis.

So to summarise you will need to create these accounts:

  • Firebase
  • Moralis

If you are new to programming, you will be required to install the following applications:

  • Node.js
  • Visual Studio Code Editor
  • Firebase Node Package

You will be taught how to create the accounts and install the following software later and there's no need to write actual code as you will be copying and pasting what we have.

This guide is primarily for Mac OS but it should work similarly for windows as well.

It will not be easy for a beginner but if you are ready for the challenge, let's get started!

Step 1: Go to the Discord Developers Portal and create an application with a bot

First things first, you’re going to want to log into the Discord developers portal navigate to “Applications” and click on “New Application” after which you will be given a prompt to put in the name of the application.

Next, you will want to click the add bot button in the bot's tab and create a bot.

At this stage, you can name it anything you want or upload your project's icon.

Next, head over to the OAuth2 tab > URL Generator and click bot, we will generate a link to invite our newly created bot to our server.

You will find the link at the bottom of this page.

Copy the link and invite your bot to the server.

Step 2: Setup your development environment

3.1 Install Node.JS

Install Node.js by clicking this link.

Select the recommended version for the Operating System you are using ( Mac or Windows ) and install it.

3.2 Install Code editor - Visual Studios

Install Visual studios Code by clicking this link.

Install the Stable version recommended for you.

Step 3: Setup the accounts

Step 3.1 Setup Firebase account

Go over to Firebase and create an account.

After creating an account, go to the console page and then click Add project.

Give it the name of the project you want to track so you can easily identify it later.

You can skip the analytics portion.

After creating the app, click on the upgrade button on the bottom left and click on the Blaze Plan as cloud functions will only work on the Blaze Plan.

However, if you view the full plan details, you will see that most of the cost starts only after you have consumed significant resources.

For our use case, the monthly cost should be negligible.

Click select plan and go ahead and fill in your billing details, remember to set a price cap for your billing at the end under $1 so you never go above a certain threshold by accident.

Click the purchase button and fill in your billing details if you haven't set it up for Google Console.

Step 3.2 Setup Moralis Account

Head over to Moralis and create an account.

After creating an account, you can see the API tab in the dashboard.

Cick Copy API Key and click default and store it somewhere safe, we will be using it to access Moralis later.

Step 4: Copying the Code and Deploying it on Firebase

This is the most complicated step so please follow it carefully.

Step 4.1 Unzip Github folder into your Desktop

Download the following code package and unzip it to your Desktop.

We will need to use the Terminal to access that folder to install the files later.

Please save the folder name without any space or special character as it may affect the installation later.

Step 4.2 Install Firebase using Visual Studio Code Terminal

Since we already have Node.js installed, we can install Firebase using Node.js in the terminal.

Go to your Visual Studio and in the top navigation, click terminal >> new terminal

You should be able to see the terminal box in the bottom of the visual studio application.

We will first need to navigate to the folder using the following terminal commands:

cd foldername > Navigate to folder
cd . . > Go back to previous folder
ls > list the folders available to navigate to

Now we will need to navigate to the correct folder to install our files.

Type ls in the terminal and press enter.

You should be able to see the options available that we can navigate to and get a sense of which folder you are currently at.

We now need to navigate to the Desktop folder so type "cd desktop" if it's available in the list, if not double check the file path required to go to your desktop, and traverse using the terminal commands till you find the desktop.

After going to the desktop, you will now need to go the folder you have downloaded.

Type cd "Name of your folder".

If at any point you have entered the wrong folder, remember you can just type "cd . ." and then ls again to list the available folders in your current location.

Once you are in the folder, we can proceed to install Firebase.

Type the following code:

sudo npm install -g firebase-tools

And then login to firebase in your terminal by typing:

firebase login

You will be prompted to login, after logging in, type

firebase init

Next, use the down arrow key and select the "Hosting" option below by pressing space and then enter.

Next, select an existing project

And use the navigation to select the project that you have created in your Firebase account.

Select the following settings and Firebase should be linked to the folder you have selected in the desktop. You are now able to easily deploy the files in here to your firebase hosting server.

Next, let's create a functions folder, type the following into the terminal

firebase init functions

And then select the following options.

Your folder should now have the following files if you have done it correctly.

Now it's time to copy the code available.

Use Visual Studio Code and open the functions folder as shown above.

You should see the following files in the editor under functions.

We will now need to copy our code and replace the code within these files. Make sure you delete the existing code.

The files we will be need to replace are

  • index.js
  • package-lock.json
  • package.json
  • env ( Rename this to ".env" , If you don't see the env file, just create it and paste our env text within )

Click the add files function to create a .env files if required.

After you have copied over the code, remember to save the code for each file individually by hitting cmd + S or going to the top navigation and clicking file > save.

Step 4.3 Add in your variables

In the .env file, we are able to set the server that we want this bot to work on and also the which bot to target.

Step 4.3.1 Add Discord Bot Token

Head over to your Discord Developer Portal and find your Bot Token

If you can't see the Token, click Reset Token to get a new one and then key it into the .env file under DISCORD_TOKEN.

Anytime you reset the token, you must edit the ".env" file and deploy it again to firebase.

Step 4.3.2 Add Moralis API Token

Next, copy and paste your Moralis API Token in to the Moralis API token field.

Step 4.3.3 Add your Server ID

Right-click your server name and copy your Server ID and paste it into the .env file.

If you can't see the Copy ID button, make sure you have developer access turned on in your settings on Discord.

And add it to the SERVER_ID field.

Step 4.3.4 Add Token Information

Fill in your Token Name, Contract Address, Ticker Symbol and Blockchain into the .env file and save.

Make sure to use the correct lookup values for the chains, for example for the Binance smart chain it's "bsc", you can find the lookup values in the website provided in the env file.

If you do not find the chain, it means the chain is currently not supported by Moralis so the price bot will not work.

Step 4.4 Deploying to Firebase

Head back to the terminal and make sure you are in the functions folder.

Tip: You can also type ls to see if "Index.js" or "Package.json" is in the list to make sure you are in the functions folder.

Next, type:

npm install

After the node modules have been installed, we will next need to deploy this version to Firebase which is the cloud hosting we will use. Type:

firebase deploy

After deployment, you should be able to see the StartBot function in your firebase account under functions.

Hover over the Request URL and copy the hover text and visit the URL in another tab.

Once you visited the URL, the website will write:

{"result":"bot started"}

This means that your bot is running fine and you should be able to see your Bot come online and then reflecting the price within the next 5 minutes.

If you face any difficulties during the creation process, feel free to drop by our new Discord Channel and go to the #support section that is specifically for project teams.

The information and publications are not intended to be and do not constitute financial advice, investment advice, trading advice or any other advice or recommendation of any sort offered or endorsed by also does not warrant that such information and publications are accurate, up to date or applicable to the circumstances of any particular case.
The Guardian
The Guardian is the guild master at WhereCrypto, helping new adventurers navigate the risky yet rewarding world of cryptocurrencies

🔥 Trending Today


⚡️ Find out about the best tokens before others

You must be logged in to submit the form.
Trusted resource for beginner to safely purchase and succeed in the cryptocurrency markets.