Skip to content

XpressAI/xai-discord

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.


Xircuits Component Library for Discord

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.

Table of Contents

Preview

Discord Bot Branch Example

DiscordBotBranchExample

Discord Bot Branch Result

DiscordBotBranchExample_result

Discord Bot Computer Vision Example

DiscordBotCVisionExample

Discord Bot Computer Vision Result

DiscordBotCVisionExample_result

Discord Bot Message Responder Example

DiscordBotMessageResponder

Discord Bot Message Responder Result

DiscordBotMessageResponder_result

Prerequisites

Before you begin, you will need the following:

  1. Python3.9+.
  2. Xircuits.

Main Xircuits Components

DiscordMessageResponder Component:

Adds a message responder that listens for a specific trigger message and responds with a predefined response. Multiple triggers and responses can be configured.

DiscordMessageResponder

DiscordPostMessage Component:

Sends a message, with an optional attachment, as a reply to the original Discord message. Can include files in the response.

DiscordPostMessage

DiscordClientInit Component:

Initializes a Discord client with default intents, enabling message content handling. Adds the client to the context for further use.

DiscordShutdownBot Component:

Adds a shutdown command to the bot, allowing administrators to shut down the bot by sending a specific message.

DiscordDeployBot Component:

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.

DiscordTriggerBranch Component:

Listens for a specific trigger message and executes a connected component when the trigger is detected. Outputs the received message and its processed content.

DiscordEchoMessage Component:

Takes a Discord message as input and constructs an echo response by prepending "You said:" to the message content.

DiscordProcessImage Component:

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.

Try The Examples

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.

Discord Bot Branch Example

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.

Discord Bot Computer Vision Example

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.

Discord Bot Message Responder Example

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.

Installation

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

Discord Related Setup

Obtaining the Bot Token

  1. Log in to the Discord Developer Portal.
  2. Click on the "New Application" button in the top-right corner.
  3. Enter a name for your application and click "Create".
  4. In the application's settings, navigate to the "Bot" tab.
  5. You will need to enable some Privileged Gateway Intents to enable bot interation. For this component library, MESSAGE CONTENT INTENT should be enough.
  6. 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.

Inviting the Bot to a Server

  1. In the Discord Developer Portal, navigate to your application's settings.

  2. Click on the "OAuth2" tab.

  3. Update the "Scopes" section and then the "Bot Permissions" section. Below is the config we have used:

    Scopes:

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

    Bot Permissions:

    • 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.
  4. Copy the generated URL from the "Scopes" section and paste it into your browser.

  5. Follow the prompts to authorize your bot and add it to your desired server.

Developers Discord

Play with our Discord bot, Xaibo here. The devs at there too.

About

Xircuits component library for Discord

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages