DEV Community

Cover image for Better Discord.js Chatbots: Revamped AI Plugin for Robo.js
WavePlay Staff for WavePlay

Posted on • Edited on • Originally published at blog.waveplay.com

Better Discord.js Chatbots: Revamped AI Plugin for Robo.js

Robo.js is a framework for creating Discord.js bots with ease and best practices by default. Plugins extend your bot's features right away!

It's now easier than ever to create AI-powered Discord bots with the latest updates to the Robo.js AI Plugin. This major update allows you to inject knowledge into your bot, enabling it to remember past interactions and respond accordingly, rewrites the core AI engine, and adds new slash commands for more dynamic interactions.

By the way, for those new, this plugin makes creating a fully customizable AI Discord chatbot as easy as one command!

Installation πŸ’»

To add this plugin to your Robo.js project:

npx robo add @robojs/ai
Enter fullscreen mode Exit fullscreen mode

New to Robo.js? Start your project with this plugin pre-installed:

npx create-robo <project-name> -p @robojs/ai
Enter fullscreen mode Exit fullscreen mode

Insights: Long-Term Memory and Knowledge Injection

One of the most significant updates is the introduction of the Insights feature, adding depth to AI interactions:

  • Contextual Long-Term Memory: Insights feature allows AI to remember past interactions for more nuanced responses per channel.
  • Default Knowledge Injection: Inject your bot with knowledge by placing documents in the project's documents folder. Any documents in this folder are automatically loaded into the AI engine's RAG model.
- /documents
    - my-first-document.txt
    - my-second-document.md
    - my-third-document.json
Enter fullscreen mode Exit fullscreen mode

This feature uses OpenAI's Assistant API in the default model. Just starting your bot will automatically set up an Assistant instance matching your bot's name, commands, system messages, documents, and more.

Insights is enabled by default, but you can disable it in the plugin configuration:

export default {
    insights: false
}
Enter fullscreen mode Exit fullscreen mode

By the way, our very own Robo, Sage, uses this feature to help people learn about Robo.js. We fed it the Robo.js documentation and a few other documents, and it's been learning ever since!

Image

Custom AI Engine Support

You can now use any AI model of your choice with the new engine configuration option. Just extend the BaseEngine class and pass it to the plugin configuration:

export default {
    engine: new MyCustomEngine()
}
Enter fullscreen mode Exit fullscreen mode

By default, this plugin still uses OpenAI's API, but you can now use any AI engine you want. This feature is ideal for developers who want to use their own AI models or integrate with other AI APIs!

Note: This feature is still in beta. We're working on improving the API and documentation for custom AI engine support.

New Slash Commands for Dynamic Interaction

These new commands add a layer of versatility to how users interact with their AI-powered bots:

  • /chat: Ideal for AI interactions when "Message Content" intent isn't enabled.
  • /imagine: Enables your bot to generate images from text prompts.
  • /ai say: A feature for moderators to communicate through the bot, with options for direct or AI-styled speech.

Image

Advanced Natural Language Command Execution

The plugin now adeptly handles complex responses and options, enhancing the AI-bot interaction:

  • Full Support for Dynamic Responses: Including embeds, files, and actions in AI-driven interactions.
  • Improved Handling of Options: Accurate processing of "Role" or "GuildMember" options in natural language commands.

Image

Simplified and More Powerful JavaScript API

The JavaScript API has been refined for better usability and more creative control:

  • Renamed and Simplified AI API: AIEngine is now AI, offering a more intuitive interface.
  • Enhanced Helper Functions: Functions like selectOne benefit from the new JSON mode, improving their reliability.

Breaking Changes: Key Updates to Note

This update includes some changes that may affect your current setup:

  • Environment Variable Update: The plugin now uses OPENAI_API_KEY as the environment variable, replacing the previous openaiKey configuration option.
  • API Renaming: The AIEngine export has been simplified and renamed to AI. This change streamlines the API and enhances its usability.

Expanded Interaction Capabilities

The update also enhances voice and web interactions, making AI bots more versatile:

  • Voice Channel Interactions: With @robojs/ai-voice, AI can now engage in voice channels. It will be updated within the next few days to support this latest update.
  • Web API Integration: @robojs/server adds a new web chat endpoint for AI interactions.

Image

This major update to the @robojs/ai opens up new possibilities for Discord.js bot developers using Robo.js. It brings sophistication and a new level of interaction to AI-powered bots!

➞ Documentation: Getting started

➞ Community: Join our Discord server

Experience the next level of bot interactions with the latest updates to the Robo.js AI Plugin!

Top comments (2)

Collapse
 
thomasbnt profile image
Thomas Bnt

Cool integration with IA and Discord!

Collapse
 
waveplay-staff profile image
WavePlay Staff

Thank you, we're very proud of it! ✨