From Good Discord Bot to Awesome Discord Bot
From Good Discord Bot to Awesome Discord Bot
A Little Background Context
Three years ago, I worked on a project where I developed crawlers for e-commerce sites. The client wanted product alerts in Discord whenever there was a significant price drop. The goal was to avoid the need for the client to monitor products all day. Instead, they wanted the flexibility to trigger crawlers based on their schedule and manage products saved in a database through Discord. Despite proposing a web application with a robust UI, the client preferred to handle everything within Discord. After diving into the Discord documentation, I built a system where the client could start, stop, add, and remove products, and receive alerts—all within Discord. It was quite innovative at the time!
Fast Forward to Today
The client has been using this system successfully, but a few months ago, they wanted to migrate it to their own server. During this process, I discovered that users sometimes struggled with the command input, as the bot previously relied on scanning messages for specific keywords to trigger actions. This setup, while functional, was prone to user errors and required remembering exact commands.
The Solution: Slash Commands
After exploring the latest Discord documentation, I found the solution in slash commands, and it has been a game changer:
- No More Guessing: Users can now trigger commands effortlessly using the intuitive
/
interface. No more remembering or guessing keywords—just a simple slash command does the trick. - Streamlined Interaction: The new system makes executing commands smoother and faster, enhancing overall efficiency.
- Enhanced User Experience: With commands clearly displayed and easily accessible, interacting with the bot has never been easier or more enjoyable.
This upgrade has transformed our bot from good to truly awesome! It’s now a more powerful and user-friendly tool, elevating the overall experience.
Here’s the code snnipset how I implemented the slash commands
from interactions import OptionType, slash_option, slash_command, SlashCommandChoice
import interactions
bot = interactions.Client()
@slash_command(name="start", description="Starts crawling")
@slash_option(
name="crawler_name",
description="Choosing the crawler you want to start",
required=True,
opt_type=OptionType.STRING,
choices=[
SlashCommandChoice(name="amazon", value="amazon"),
SlashCommandChoice(name="bestbuy", value="bestbuy"),
SlashCommandChoice(name="woot", value="woot"),
]
)
async def start_command(ctx: interactions.SlashContext, crawler_name:str):
await ctx.send(f"start {crawler_name}")
@slash_command(name="stop", description="Helps to stop the crawler")
@slash_option(
name="crawler_name",
description="Choosing the crawler you want to start",
required=True,
opt_type=OptionType.STRING,
choices=[
SlashCommandChoice(name="amazon", value="amazon"),
SlashCommandChoice(name="bestbuy", value="bestbuy"),
SlashCommandChoice(name="woot", value="woot"),
]
Thinking of making similar improvements? Slash commands might be just what you need to take your bot to the next level!