Component Libraries •
Project Templates
Docs •
Install •
Tutorials •
Developer Guides •
Contribute •
Blog •
Discord
Xircuits Component Library to interface with Discord! Create Discord Bots in seconds.
Uses discord.py as backend.
This library enables Xircuits to integrate with Discord, allowing seamless interaction with Discord bots and servers. It simplifies managing bot tokens, sending and receiving messages, and handling events in Discord channels and threads.
Before you begin, you will need the following:
- Python3.9+.
- Xircuits.
Adds a message responder that listens for a specific trigger message and responds with a predefined response. Multiple triggers and responses can be configured.
Sends a message, with an optional attachment, as a reply to the original Discord message. Can include files in the response.
Initializes a Discord client with default intents, enabling message content handling. Adds the client to the context for further use.
Adds a shutdown command to the bot, allowing administrators to shut down the bot by sending a specific message.
Deploys the Discord bot using the provided token. It runs the bot either in a standalone script or within Xircuits, handling events such as incoming messages.
Listens for a specific trigger message and executes a connected component when the trigger is detected. Outputs the received message and its processed content.
Takes a Discord message as input and constructs an echo response by prepending "You said:" to the message content.
Processes an image attachment from a Discord message triggered by a specified message. Outputs the image data and triggers a connected component for further processing.
We have provided an example workflow to help you get started with the Discord component library. Give it a try and see how you can create custom Discord components for your applications.
The DiscordBotBranchExample.xircuits
workflow creates a Discord bot that listens for messages starting with @test
and replies with "You have said: [message]". It can also shut down using the command $ayonara
.
The DiscordBotCVisionExample.xircuits
workflow creates a Discord bot that listens for the command $predict
with an image attachment. The bot processes the image using a MobileNetV2 model for predictions and responds with the predicted class. It also includes a shutdown command $ayonara
.
The DiscordBotMessageResponder.xircuits
workflow sets up a Discord bot that listens for specific text commands and responds with predefined messages. For instance:
$test
: The bot replies with "it works!".$Hello there!
: The bot replies with "General Kenobi!".
Additionally, the bot can be shut down using the $ayonara
command.
To use this component library, ensure that you have an existing Xircuits setup. You can then pull and install this library using:
xircuits-submodules xai_discord
Otherwise you can do it manually by cloning and installing it.
# base Xircuits directory
git clone https://github.com/XpressAI/xai-discord xai_components/xai_discord
pip install -r xai_components/xai_discord/requirements.txt
- Log in to the Discord Developer Portal.
- Click on the "New Application" button in the top-right corner.
- Enter a name for your application and click "Create".
- In the application's settings, navigate to the "Bot" tab.
- You will need to enable some
Privileged Gateway Intents
to enable bot interation. For this component library,MESSAGE CONTENT INTENT
should be enough. - Under the "Token" section, click "Copy" to copy the bot token to your clipboard. You may need to Reset the token if it is a new bot.
-
In the Discord Developer Portal, navigate to your application's settings.
-
Click on the "OAuth2" tab.
-
Update the "Scopes" section and then the "Bot Permissions" section. Below is the config we have used:
- bot: For OAuth2 bots, this puts the bot in the user's selected guild by default.
- applications.commands: Allows your app to use commands in a guild.
- Read Messages / View Channels: Allows the bot to read and view the channels in the server.
- Send Messages: Allows the bot to send messages in text channels.
- Read Message History: Allows the bot to read the message history of text channels.
-
Copy the generated URL from the "Scopes" section and paste it into your browser.
-
Follow the prompts to authorize your bot and add it to your desired server.
Play with our Discord bot, Xaibo here. The devs at there too.