Chapter 70 – Build a Discord Bot Using Python, Hikari, Lightbulb, MongoDB

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.

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

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

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

import 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.

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)

async def nftMessage(event):

print(event)

if event.is_human:

if myCollection.find_one({'messageA': 'id123'})['greetingMessage'] in event.content.strip().lower():

return await event.message.respond(f'Hello buddy! please tell me more about your question?')

elif myCollection.find_one({'messageA': 'id1234'})['greetingMessage'] in event.content.strip().lower():

return await event.message.respond(f'Hello buddy! Whats up?')

else:

return 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.

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

@bot.command

@lightbulb.command("nft", "Return the latest NFTs Collection")

@lightbulb.implements(lightbulb.PrefixCommand, lightbulb.SlashCommand)

async def nftS(ctx: lightbulb.Context):

return await ctx.respond(f'This is our latest NFT Collection, please check it out: https://testnets.opensea.io/assets/goerli/0x8eeb73f75e6d80a6a21302d1ec36d0ead0ceb295/0')

bot.run()

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

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:

Q1: What is a Discord Chatbot?

A: A Discord Chatbot is a software application that integrates with the Discord platform and automates various tasks and functions within Discord servers.

Q2: What can a Discord Chatbot do?

A: 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.

Q3: How can a Discord Chatbot benefit my eCommerce business?

A: 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.

Q4: How can I integrate a Discord Chatbot with my eCommerce website?

A: 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.

Q5: Are Discord Chatbots customizable?

A: 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.

Q6: Can a Discord Chatbot generate analytics and insights for my eCommerce business?

A: 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.

Q7: How can I promote my eCommerce products using a Discord Chatbot?

A: 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.

Q8: Is it possible to integrate third-party services with a Discord Chatbot?

A: Yes, Discord Chatbots can be integrated with various third-party services such as payment gateways, customer support platforms, and CRM systems to streamline your eCommerce operations.

Q9: Can a Discord Chatbot assist in handling customer support queries?

A: 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.

Q10: Are there any limitations to what a Discord Chatbot can do?

A: 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.