blog details
author


blog detail

Discord is a social media platform where large numbers of people can interact in the form of a community. Currently, it’s the most harmonious platform for NFT projects as they’re community-oriented. Furthermore, the platforms facilitate NFTs trading or brand NFT marketing through their freedom communication features and integration space with Crypto wallets, such as Collabland, Metamask. Last but not least, it also facilitates NFT gating in private communities.

In this article, I would walk through how to build a discord bot to further increase communication and navigation efficiency using Python, MongoDB, Hikari, and Lightbulb.

Table of Contents: Build a Discord Bot Using Python, Hikari, Lightbulb, MongoDB

Discord Bot Account: Discord Application, Token, Permission Options, Authentication Link

First thing first, we need to create a discord bot account to get the access token and set up some permission in the discord communication.

Step 1: Go to the discord developer portal and log in using your discord account

Here is to create a new application

blog detail

Step 2: Add a new bot, Select Permission Options and Authorise the. Integration with your Discord Account using the generated URL after having confirmed the permission options

Options for reference:
Scopes: Bot, applications.commands
Permission: Administration

blog detail

blog detail

blog detail

User Message Receive and Response using Hikari

Secondly, it’s to create an auto-reply based on the messages from the users. Auto-reply 1to1 message strategy also matters, so I will further share in another article. In this piece, I would share the core framework of building this automatic conversation.

Step 1: Install and import Hikari, Lightbulb Module (pip3 install Hikari)

import hikari\nimport lightbulb

Step 2: Connect with Discord Bot Using LightBulb

In the integration, the bot token is the unique key to identify which bot you are using in the discord account. Additionally, please be sure to set up the intents which tell the system all messages can be handled by the bot

bot = lightbulb.BotApp(token="your bot token generated in the bot account", intents=hikari.Intents.ALL_MESSAGES, prefix="!")

If it’s connected, the live bot account would show up on the right side as well with other users and yourself.

blog detail

Step 3: Set up the auto-reply by events

@bot.listen() is the method to capture messages from users. Basically, there are two places . to capture messages. One is the public conversion guild, such as messages from channels, and the community and the other is the private message, which is the DM.

Here are the code samples for building the auto-reply in the DM with MongoDB and Hikari.

@bot.listen(hikari.DMMessageCreateEvent)\nasync def nftMessage(event):\nprint(event)\nif event.is_human:\nif myCollection.find_one({'messageA': 'id123'})['greetingMessage'] in event.content.strip().lower():\nreturn await event.message.respond(f'Hello buddy! please tell me more about your question?')\nelif myCollection.find_one({'messageA': 'id1234'})['greetingMessage'] in event.content.strip().lower():\nreturn await event.message.respond(f'Hello buddy! Whats up?')\nelse:\nreturn await event.message.respond(f'Tied up with something at the moment, I would come back to you asap')

Create a list of Slash Keywords & Navigators

Slash keywords basically are those specific words for users to get specific information without asking questions. It looks like the navigators. For example, if you are running an NFTs trade community, you can list a series of NFT name keywords, and users can get all information regarding these NFTs automatically in the conversion box.

blog detail

In this section, we need to use lightbulb commands. Here are the code samples for creating one slash keyword FYI

@bot.command\n@lightbulb.command("nft", "Return the latest NFTs Collection")\n@lightbulb.implements(lightbulb.PrefixCommand, lightbulb.SlashCommand)\nasync def nftS(ctx: lightbulb.Context):\nreturn await ctx.respond(f'This is our latest NFT Collection, please check it out: https://testnets.opensea.io/assets/goerli/0x8eeb73f75e6d80a6a21302d1ec36d0ead0ceb295/0')\nbot.run()

In each slash command, it can include the name and description. Also, you can customiz. e the responding message as well. Here is a sample of Easy2Digital NFTs.

blog detail

Full Python Script of Discord Bot using Hikari, Lightbulb, MongoDB, and Python

If you are interested in Python Tutorial 70 – Build a Discord Bot Using Python, Hikari, Lightbulb, MongoDB, please subscribe to our newsletter by adding the message “Chapter 70”. We would send you the script immediately to your mailbox.

I hope you enjoy reading Python Tutorial 70 – Build a Discord Bot Using Python, Hikari, Lightbulb, MongoDB. If you did, please support us by doing one of the things listed below, because it always helps out our channel.




FAQ

A Discord Chatbot is a software application that integrates with the Discord platform and automates various tasks and functions within Discord servers.
A Discord Chatbot can perform a wide range of functions such as moderating the server, managing user roles and permissions, providing automated responses and commands, playing music, and much more.
A Discord Chatbot can enhance customer engagement and support by providing automated responses to frequently asked questions, managing customer orders and inquiries, and even facilitating sales through integrations with eCommerce platforms.
To integrate a Discord Chatbot with your eCommerce website, you can use Discord APIs and webhooks to send and receive data between your website and the Discord platform.
Yes, Discord Chatbots can be customized to suit the specific needs of your eCommerce business. You can define custom commands, responses, and behavior for your Chatbot.
Yes, a Discord Chatbot can track and analyze user interactions, server activity, and other metrics to provide valuable insights that can help you optimize your eCommerce strategy.
You can configure your Discord Chatbot to automatically showcase new products, offer exclusive discounts, and even run promotional campaigns through Discord server announcements and direct messages.
Yes, Discord Chatbots can be integrated with various third-party services suchs as payment gateways, customer support platforms, and CRM systems to streamline your eCommerce operations.
Absolutely! A Discord Chatbot can provide automated responses to common customer queries, escalate complex issues to human support agents, and even create support tickets for efficient resolution.
While Discord Chatbots are versatile, their capabilities are ultimately limited by the Discord platform’s APIs and the functionality you choose to implement. However, with proper configuration and customization, you can achieve significant automation and efficiency for your eCommerce business.

No Comment at the moment...