• About
  • Landing Page
  • Buy JNews
SB Crypto Guru News- latest crypto news, NFTs, DEFI, Web3, Metaverse
  • HOME
  • BITCOIN
  • CRYPTO UPDATES
    • GENERAL
    • ALTCOINS
    • ETHEREUM
    • CRYPTO EXCHANGES
    • CRYPTO MINING
  • BLOCKCHAIN
  • NFT
  • DEFI
  • WEB3
  • METAVERSE
  • REGULATIONS
  • SCAM ALERT
  • ANALYSIS
No Result
View All Result
  • HOME
  • BITCOIN
  • CRYPTO UPDATES
    • GENERAL
    • ALTCOINS
    • ETHEREUM
    • CRYPTO EXCHANGES
    • CRYPTO MINING
  • BLOCKCHAIN
  • NFT
  • DEFI
  • WEB3
  • METAVERSE
  • REGULATIONS
  • SCAM ALERT
  • ANALYSIS
No Result
View All Result
SB Crypto Guru News- latest crypto news, NFTs, DEFI, Web3, Metaverse
No Result
View All Result

Blockchain Discord Bot – Construct a Discord Bot for On-Chain Occasions

SB Crypto Guru News by SB Crypto Guru News
November 10, 2022
in Web3
0 0
0
Blockchain Discord Bot – Construct a Discord Bot for On-Chain Occasions


With regards to crypto communities, Discord is an especially widespread platform. Therefore, we need to present you methods to construct a Discord bot for on-chain occasions, and due to the Moralis Streams API, you’ll be able to construct a crypto monitor Discord bot effortlessly. All it takes is a free Moralis account, a Discord server, and a few easy JavaScript programming. Furthermore, constructing a Discord bot is lots less complicated than you may suppose, and on this article, we’re going to perform this in 5 easy steps:

  1. Setting Up a Easy NodeJS Categorical Backend   
  2. Including a New Moralis Stream 
  3. Verifying the Webhook Sender
  4. Setting Up a Discord Bot 
  5. Implementing an Instance Blockchain Discord Bot  

Moreover, it shouldn’t take greater than twenty minutes to set issues up. Additionally, because of Moralis’ cross-chain interoperability, the perfect factor about our Discord bot is you can hearken to any on-chain occasion on Ethereum and different EVM-compatible chains. However, for the sake of this tutorial, we’ll concentrate on the Polygon testnet (Mumbai).

Shifting ahead, we’ll first be sure that you all know what a Discord bot is. Then, we’ll dive into immediately’s tutorial. Nevertheless, earlier than we present you methods to construct a Discord bot, we’ll check out a demo, which is able to enable you higher perceive what a crypto monitor Discord bot is. As well as, by seeing our demonstration, you’ll additionally be capable of determine whether or not or not you need to concentrate on constructing a Discord bot to your personal functions. With that stated, if you happen to already know what a Discord bot is, be happy to dive proper into our blockchain Discord bot tutorial.   

Join Moralis' Discord Channel and Moralis Magazine.

What’s a Discord Bot?

If you happen to’ve accomplished any on-line purchasing, you’ve in all probability encountered chatbots. These bots are packages that assist automate sure processes. Furthermore, when these kinds of AI-driven instruments are used to automate duties on Discord servers, they’re known as Discord bots. As chances are you’ll know, Discord servers supply many options, a lot of which might be automated. 

Showing a crypto Discord bot on a user's smartphone.

So, what precisely is a blockchain Discord bot? It’s a Discord bot that triggers a particular motion on a particular Discord server when a specific on-chain occasion (the one which the bot listens to) happens. Therefore, a crypto monitor Discord bot is a really sensible instrument for all kinds of crypto Discord communities. In any case, it will probably add a number of worth to personal and public Discord channels. 

Discord logo next to a virtual bot.

It’s additionally value mentioning that the Discord bot function is obtainable on Discord’s developer portal. As such, you don’t should do any severe coding to create Discord bots. As an alternative, you’ll be able to merely choose among the many given choices and use Discord’s pre-built options. You’ll get to see this, as we present you methods to construct a Discord bot within the part under. 

The best way to Construct a Discord Bot for Blockchain Occasions

Constructing a Discord bot for crypto is easy, because of Moralis’ Streams API. This highly effective instrument lets you stream blockchain knowledge into your backend (on this case, Discord’s backend) by way of webhooks. To entry this highly effective instrument, you solely want a free Moralis account. In fact, you additionally have to determine what on-chain occasions curiosity you. This may decide whether or not you’ll be able to hearken to an current good contract or if you happen to’ll have to create and deploy your good contract first. Nevertheless, for the sake of this tutorial, we’ll use an current good contract. In truth, to keep away from any confusion, begin by specializing in our instance Web3 contract. 

Additionally, to construct your personal crypto monitor Discord bot following our lead, you will want the next instruments:

  • A Moralis account, which you’ll create without spending a dime!
  • Some kind of code editor or IDE. We’ll be utilizing Visible Studio Code (VSC). 
  • A Discord server and entry to Discord’s developer portal.
  • A blockchain explorer. Our instance Web3 contract is on the Mumbai community, so we’ll be utilizing PolygonScan.
  • The Postman platform (optionally available). It is a instrument that can assist you make API calls to completely different posts, get endpoints, and so forth.
Discord.js Basics with Discord title.

Furthermore, we’ll take you thru the next steps:

  1. Setting Up a Easy NodeJS Categorical Backend   
  2. Including a New Moralis Stream 
  3. Verifying the Webhook Sender
    1. It’s essential to be sure that solely Moralis could make a webhook put up.
  4. Setting Up a Discord Bot   
  5. Implementing an Instance Blockchain Discord Bot
    1. Sending messages with Discord.js

Now, as talked about above, earlier than we present you methods to construct a Discord bot, let’s check out an illustration. 

Our Crypto Monitor Discord Bot – Demo

So, that is our instance Discord server, which we created for the sake of this tutorial:

Showing a Discord channel that displays a message that says Build a Blockchain Discord Bot!

Trying on the above screenshot, you’ll be able to see our crypto monitor Discord bot (“DonationBot”) in the precise sidebar. Subsequent, we use PolygonScan to work together with our instance “donationExample” good contract. Clearly, that is the good contract that our instance blockchain Discord bot listens to.

Showing a Web3 wallet modal with a confirmed transaction.

The above picture exhibits you that by clicking on the “Write” button on PolygonScan’s web page for our instance Web3 contract, we really execute an on-chain transaction utilizing MetaMask. Additionally, as you’ll be able to see above, we donated six MATIC tokens. Lastly, as quickly as our transaction goes via, our Discord bot posts a message informing our Discord members about this donation:

As you’ll be able to see, the message contains the donor’s tackle and the donated quantity. Nevertheless, the important thing level is that the on-chain occasion (a donation transaction) triggered our Discord bot. 

If you happen to discover this function helpful, make certain to comply with our lead within the upcoming sections, the place we’ll cowl constructing a Discord bot that listens to on-chain occasions (just like the one introduced on this demo). 

Setting Up a Easy NodeJS Categorical Backend   

If you wish to discover ways to construct a Discord bot for on-chain occasions the simple means, begin with a easy NodeJS Categorical dapp. You will discover the starter code in our GitHub repo for this tutorial. Additionally, be sure you have “ngrok” put in to create a “ngrok” tunnel to your Categorical dapp. To do that, open a brand new terminal and enter the next command:

ngrok http 3000

Observe: In case you’re utilizing a unique port, make certain to switch “3000” accordingly.

Because of working the above command, you’re going to get an tackle the place your Categorical dapp will probably be working:

Subsequent, you need to set up all of the dependencies with this command:

npm i categorical moralis discord.js dotenv

Furthermore, we suggest that you just additionally set up “nodemon” so that you just’ll be capable of view modifications while not having to cease and restart your server. Therefore, additionally use the command under:

npm i nodemon

With the dependencies in place, open your “bundle.json” file and add the “begin” script for “nodemon“:

Lastly, you’re able to run your dapp utilizing the command under:

npm run begin

Including a New Moralis Stream

Along with your dapp working, it’s time to create a brand new Moralis Stream. To do that, you want your Moralis account. So, in case you haven’t created your account but, accomplish that now. Utilizing your credentials, you’ll entry your admin space. From there, you’ll be capable of go to the “Streams” web page, the place you want to click on on the “New Stream” button:

Showing Moralis' Streams landing page with an API key credential.

Then, choose the “Create From Scratch” possibility:

User clicking on the Create From Scratch button on the Streams page.

Subsequent, you want to enter a number of particulars associated to the good contract you need to hearken to. That is a necessary step of the “methods to construct a Discord bot” course of. Furthermore, sooner or later, you’ll need to use your personal good contract or different already deployed contracts. Nevertheless, for the sake of this tutorial, we suggest you employ our instance good contract (the “exampleDonation” contract).

Acquiring and Getting into Good Contract Particulars

By specializing in the “exampleDonation” contract, go to PolygonScan and duplicate this good contract’s tackle:

Showing a contract's address on PolygonScan.

Then, return to your “Add new Stream” window and paste the above-copied tackle into the designated spot:

Shifting on, scroll down so as to add your new Moralis Stream’s description. This may be no matter you need; nevertheless, to keep away from any pointless confusion, you should use “New Donation”:

Description of the user's blockchain Discord bot project - New Donation.

Subsequent, paste your “ngrok“ tackle within the “Webhook URL” entry discipline and add “/webhook” on the finish: 

Entering webhook as the URL.

So far as the tag goes, you’ll be able to go along with “NewDonation”:

Tag for the project is NewDonation.

With regards to deciding on networks, you want to be sure you choose the community on which the good contract you need to hearken to is. If you happen to keep in mind, the “exampleDonation” contract is on Polygon’s testnet. Thus, make certain to pick out the “Polygon Mumbai” possibility:

Showing the user to click on the Polygon Mumbai network.

Then, you need to choose the “Native Transactions” possibility (donations are made in MATIC):

Checmarking the Native Transaction option.

Moreover, make certain to activate “Occasion Emittance”:

Enabling Event Emittance.

Subsequent, return to PolygonScan to repeat the good contract’s ABI:

User copying the contract's ABI address.

By pasting the copied ABI within the designated space, you’ll get to pick out the occasion of this good contract:

Pasting the ABI into the designated area.

Lastly, create your new Moralis Stream by clicking on the “Create Stream” button within the bottom-right nook. Consequently, it’s best to get the “New Stream Created” success message. You also needs to be capable of see your Moralis Stream on the backside of the “Stream” web page:

Seeing the New Stream Created message.

Now you can check your Moralis Stream. To see precisely how to try this, use the video on the backside of the article, beginning at 5:36.

Verifying Webhook Sender 

With the present “index.js” code (as offered within the “starter.js” file”), anybody along with your webhook tackle could make a put up request. As such, you have to implement the required tweaks to confirm the webhook sender. First, import Moralis on the prime of your “index.js” file:

const Moralis = require("moralis").default;

Then, initialize an occasion of Moralis by including the next strains of code:

Moralis.begin({
  apiKey: course of.env.APIKEY,
})

Trying on the strains of code above, you see that you just want your Moralis Web3 API key. It’s essential to copy it out of your Moralis admin space:

Copying the Web3 API key on the Web3 API page on Moralis' Admin Panel.

Subsequent, return to VSC, create a brand new file (“.env”), and paste your Web3 key subsequent to “APIKEY”:

The .env file inside VSC.

Along with your Web3 API key in place, return to the “index.js” file and require “dotenv” on the prime:

require("dotenv").config();

Now, you need to ensure that your dapp begins solely after beginning Moralis by placing “app.pay attention” inside “then”:

Moralis.begin({
  apiKey: course of.env.APIKEY,
}).then(() => {
  app.pay attention(port, () => {
    console.log(`Listening to streams`);
  });
});

Then, you additionally need to take a look at “headers” and add Moralis’ “verifySignature”:

Seeing the verifySignature code snippet.

Observe: We encourage you to check your present progress by following our in-house skilled’s lead (video under at 10:20). That is the place you’ll use Postman.

Setting Up a Discord Bot   

Demonstrating methods to construct a Discord bot wouldn’t be full with out us displaying you methods to arrange a Discord bot. So, begin by going to your Discord account. There, create a brand new server (“Blockchain Notify”). If you happen to’ve by no means created a Discord server earlier than, make certain to make use of the video under (11:30). 

After you have your server prepared, it’s time so as to add a brand new Discord bot to that server. To do this, go to Discord’s developer portal and register. Then go to the “Purposes” web page and click on on the “New Utility” button:

Adding a Discord blockchain bot on the applications page on discord.com.

Subsequent, title your software, test the field, and hit the “Create” button: 

The box where a user can name their application and click on create.

You too can add an icon to your software:

General Information page.

Then, you need to choose the “Bot” possibility, click on on the “Add Bot” button, and ensure with a click on on “Sure, do it!”:

The module showing a message that says Add a Bot to this App.

Shifting ahead, you need to increase “OAuth2” and click on on the “URL Generator” possibility:

User checkmarking the "bot" option.

Subsequent, as indicated within the picture above, test the “bot” scope. Then, scroll down and test the “Ship Message” permission:

User checking the Send Message permission.

As proven within the above screenshot, copy the generated URL. By pasting that URL into your browser, you’ll be capable of choose a server to which you need to add that bot:

Discord.com page showing the prompt box asking if user wants to add a blockchain Discord bot.

To finalize this step of constructing a Discord bot for crypto, you’ll additionally have to click on on the “Authorize” button and ensure that you’re human:

Checkmarking the I Am Human message.

Now, you’ll be able to shut that tab and go to your Discord. If you happen to’ve adopted our directions, it’s best to now have the “DonationBot” bot in your “Blockchain Notify” Discord server:

Showing the DonationBot on the Discord server.

Implementing an Instance Blockchain Discord Bot – Sending Messages with Discord.js

On this last step of our “methods to construct a Discord bot” quest, you want to add the required strains of code to make sure that the above-created bot turns into a crypto monitor Discord bot. Therefore, return to your “index.js” script and import “discord.js” on the prime:

const discord = require("discord.js");   

Subsequent, create a Discord shopper just under the imports:

const shopper = new discord.Consumer({
    intents: [],
  });

shopper.login(course of.env.PASS);

Trying on the backside line of the code above, you’ll be able to see that you want to add the “PASS” variable to your “.env” file. To get this variable, return to your “DonationBot” software (the “Bot” possibility) and click on on the “Reset Token” button. Then copy the token:

User copying. the token.

Shifting on, go to your “.env” file, create the “PASS” variable, and paste within the above-copied token:

Inside the .env file in VSC.

Subsequent, go to your Discord server, and duplicate your channel ID (right-click on the channel through which you need your bot to put up messages):

User copying the ID.

Return to the “.env” file and create a brand new variable that can retailer the above-copied ID:

User pasting the ID into the channel variable inside VSC.

Along with your variables in place, you’ll be able to add the required strains of code inside “strive”:

    let from = physique.txs[0].fromAddress;
    let quantity = Quantity(physique.txs[0].worth / 1E18);

    const channel = await shopper.channels.fetch(course of.env.CHANNEL);
    channel.ship(`New Donation submitted by ${from}, for ${quantity.toFixed(2)} MATIC!!!!`);

Observe: You’ll be able to entry the last code on GitHub.

With the above strains of code in place, you’ve efficiently accomplished all 5 steps concerned within the “methods to construct a Discord bot” implementation. Now, make certain to take your bot for a spin. For steerage, use the video under (17:34).

Final however not least, right here’s the video model of our “methods to construct a Discord bot” tutorial we’ve been referencing all through the article:

Blockchain Discord Bot – Construct a Discord Bot for On-Chain Occasions – Abstract

We lined fairly a distance in immediately’s article. First, you had an opportunity to be taught what a Discord bot is. We additionally made certain you realize what a crypto monitor Discord bot is. With the fundamentals below your belt, you had a possibility to comply with our lead. Furthermore, by taking you thru the 5 main steps, we offered you with all the small print associated to constructing a Discord bot. These 5 steps included:

  1. Setting Up a Easy NodeJS Categorical Backend   
  2. Including a New Moralis Stream 
  3. Verifying the Webhook Sender
  4. Setting Up a Discord Bot 
  5. Implementing an Instance Blockchain Discord Bot  

Nonetheless, we additionally shared a video tutorial containing further particulars about constructing a Discord bot for on-chain occasions. 

We advise you employ the “methods to construct a Discord bot” data obtained above to construct your personal crypto monitor Discord bot for one more good contract. That means, you’ll correctly solidify your data. Alternatively, chances are you’ll need to discover different blockchain growth matters and create all kinds of dapps. If that’s the case, it’s best to use the Moralis docs, the Moralis YouTube channel, and the Moralis weblog. In any case, these retailers have the facility that can assist you develop into a Web3 developer without spending a dime. For instance, a few of our newest matters present you methods to program good contracts on Solana, add recordsdata to IPFS, mint a coin on Solana, methods to create an NFT venture, and rather more. 

In fact, you may as well take a extra skilled method to your crypto training. By enrolling in Moralis Academy, you’ll be able to develop into blockchain licensed and considerably enhance your possibilities of touchdown a crypto job. To create a correct basis, we encourage you to start out with the course specializing in blockchain and Bitcoin fundamentals.





Source link

Tags: Bitcoin NewsblockchainBotBuildCrypto NewsCrypto UpdatesDiscordEventsLatest News on CryptoOnChainSB Crypto Guru News
Previous Post

Philippines-Primarily based Neobank Tonik Provides New Lending Merchandise

Next Post

Finest 3 Ethereum-based tokens to look at when the bull market returns

Next Post
Finest 3 Ethereum-based tokens to look at when the bull market returns

Finest 3 Ethereum-based tokens to look at when the bull market returns

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Trending
  • Comments
  • Latest
Meta Pumps a Further  Million into Horizon Metaverse

Meta Pumps a Further $50 Million into Horizon Metaverse

February 24, 2025
How to Get NFT Balances with One RPC Call – Moralis Web3

How to Get NFT Balances with One RPC Call – Moralis Web3

August 30, 2024
How to Get Token Prices with an RPC Node – Moralis Web3

How to Get Token Prices with an RPC Node – Moralis Web3

September 3, 2024
Chiliz Chain Deep Dive – Why Build on Chiliz Chain? – Moralis Web3

Chiliz Chain Deep Dive – Why Build on Chiliz Chain? – Moralis Web3

September 10, 2024
Samsung Unveils ‘Moohan’ to Compete with Quest, Vision Pro

Samsung Unveils ‘Moohan’ to Compete with Quest, Vision Pro

January 29, 2025
Exploring Moonbeam – Why Build on Moonbeam? – Moralis Web3

Exploring Moonbeam – Why Build on Moonbeam? – Moralis Web3

September 11, 2024
NVIDIA Unveils TensorRT for RTX to Boost AI Application Performance

NVIDIA Unveils TensorRT for RTX to Boost AI Application Performance

0
Liquidity Levels Show XRP Price Is Headed Up, But Must Cross .40 First

Liquidity Levels Show XRP Price Is Headed Up, But Must Cross $2.40 First

0
Shopify Merchants Can Now Receive USDC or Local Currency

Shopify Merchants Can Now Receive USDC or Local Currency

0
Hong Kong Builds Crypto Tracker to Catch Laundered Money

Hong Kong Builds Crypto Tracker to Catch Laundered Money

0
Mattel, OpenAI Sign Deal to Bring ChatGPT to ‘Iconic’ Toys

Mattel, OpenAI Sign Deal to Bring ChatGPT to ‘Iconic’ Toys

0
Now accepting interns – Join the Ethereum Season of Internships

Now accepting interns – Join the Ethereum Season of Internships

0
Shopify Merchants Can Now Receive USDC or Local Currency

Shopify Merchants Can Now Receive USDC or Local Currency

June 12, 2025
Liquidity Levels Show XRP Price Is Headed Up, But Must Cross .40 First

Liquidity Levels Show XRP Price Is Headed Up, But Must Cross $2.40 First

June 12, 2025
Mattel, OpenAI Sign Deal to Bring ChatGPT to ‘Iconic’ Toys

Mattel, OpenAI Sign Deal to Bring ChatGPT to ‘Iconic’ Toys

June 12, 2025
Coinbase Announces Bitcoin Rewards Credit Card, Offering Up To 4% BTC Back On Everything

Coinbase Announces Bitcoin Rewards Credit Card, Offering Up To 4% BTC Back On Everything

June 12, 2025
Crypto Expert Puts Ethereum Price At ,500 With Head And Shoulders Emergence

Crypto Expert Puts Ethereum Price At $19,500 With Head And Shoulders Emergence

June 12, 2025
Hong Kong teams up with university to tackle crypto laundering with tech

Hong Kong teams up with university to tackle crypto laundering with tech

June 12, 2025
SB Crypto Guru News- latest crypto news, NFTs, DEFI, Web3, Metaverse

Find the latest Bitcoin, Ethereum, blockchain, crypto, Business, Fintech News, interviews, and price analysis at SB Crypto Guru News.

CATEGORIES

  • Altcoin
  • Analysis
  • Bitcoin
  • Blockchain
  • Crypto Exchanges
  • Crypto Updates
  • DeFi
  • Ethereum
  • Metaverse
  • Mining
  • NFT
  • Regulations
  • Scam Alert
  • Uncategorized
  • Web3

SITE MAP

  • Disclaimer
  • Privacy Policy
  • DMCA
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact us
  • Disclaimer
  • Privacy Policy
  • DMCA
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact us

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
No Result
View All Result
  • HOME
  • BITCOIN
  • CRYPTO UPDATES
    • GENERAL
    • ALTCOINS
    • ETHEREUM
    • CRYPTO EXCHANGES
    • CRYPTO MINING
  • BLOCKCHAIN
  • NFT
  • DEFI
  • WEB3
  • METAVERSE
  • REGULATIONS
  • SCAM ALERT
  • ANALYSIS

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.