Skip to content

nicolodiamante/MAIA

Repository files navigation

MAIA

Discord, a renowned digital platform, has seen massive use in recent years as it combines text, voice, and video communication, bringing people together over common interests. One of its pivotal features is the ability to integrate AI chatbots like ChatGPT, which can remarkably enhance user experience. Among these, MAIA (Messaging Artificial Intelligent Assistant) is a bot that embeds the power of ChatGPT, ensuring friendliness and utility at its best. The bot not only enlivens your Discord server but also keeps it informed and entertained, ultimately serving as a powerful tool to boost user engagement in your channel. In essence, MAIA serves as a valuable tool for those seeking to leverage AI technology within their Discord communities.



OpenAI + Discord



Requirements to get MAIA to work within Discord Server

Create the bot

It's time to construct our Discord bot. To start, visit the Discord Developers Applications page. If you're not logged in yet, make sure to sign in. You'll see an option labelled "Create Application" on the right side of the page, click on it, then assign a name to your application. You are free to use any name you like. For example, I'll name mine "MAIA".



Create An Application



Begin by assigning an avatar to your application. Afterwards, proceed to the "bot" section located on the left-hand side of your screen and click "Create Bot". Once your bot has been created, adjust the following settings according to your preferences:

  1. Deactivate the "Public Bot" setting if you wish to prevent others from inviting your bot.

    Toggle Off  Public Bot

  2. Activate all the "Intense Settings":

    Toggle On  Presence Intent

    Toggle On  Server Member Intent

    Toggle On  Message Content Intent

  3. Select OAuth2, which is on your screen's left, and choose "↳ URL Generator" to create an invitation link for your Discord bot. Within the scope section, select:

    Check Mark  Bot

    Check Mark  Application.commands (If you plan to include / commands)

    Proceed by navigating to the bot permissions section below and select:

    Check Mark  Send messages

    To add the bot to your server, follow the standard procedure as with other bots. After enabling this setting, scroll down to find the generated URL. Copy this URL, then go to your Discord server. Paste the link into the chat and send it. Click the sent link to invite the bot to your server.

Discord URL

  1. Lastly, to obtain the bot token, click on "Bot" on the left side of your screen and select "Reset Token". This will produce a long string beneath the bot's username. Ensure you copy it. Once you navigate away, this key won't be accessible again. If lost, you'll have to reset the token.



Discord App Token



  1. After copying the token, open your Discord app and navigate to your server. Paste the token and click on the link—follow the prompted steps to allow your bot into your server. Once you've invited the bot, it will appear on the Member list on your right-hand side; it will be offline initially.



MAIA On Discord



With the bot now created and added to your Discord server, the next steps are straightforward, but they do involve some specific links and prerequisites for seamless operation. It's time to gather all the necessary keys. We've already created the Discord token; now it's time to create your OpenAI API Key if you don't already have one. This key is important for integrating ChatGPT with Discord.


Create your OpenAI API Key

To use MAIA's services in Discord, obtaining an OpenAI API key is critical. This key can be generated from your existing OpenAI account; if you don't have an OpenAI account, easily create one by visiting this link. This secret key is essential for authentication verification. Below is a detailed guide on acquiring the key:

  1. Log in to your OpenAI account.
  2. Search for the "Create new secret key" option and click on it.

OpenAI new secret key

After acquiring the API Key, integrating ChatGPT's services into Discord is fairly simple. Remember, once you copy the key and close the pop-up, you cannot access it again. Therefore, store the key in a secure location.

OpenAI API Key



Getting Started

Now you've created the application and gathered all the necessary keys to operate the bot. You need to download the repository. Here are the two methods you can choose from:

Automatic Download via curl: Simply execute the following command in your terminal to quickly download and seamlessly install the utility:

zsh -c "$(curl -fsSL https://raw.githubusercontent.com/nicolodiamante/MAIA/HEAD/bootstrap.zsh)"

Manual Cloning: For those who prefer a hands-on approach, you can manually clone the repository to your desired location:

git clone https://github.com/nicolodiamante/MAIA.git ~/MAIA

Post-Download Steps

Directory Navigation & Script Execution: Navigate to the root directory of the repository, and then execute the installation script using the following command:

source utils/install.sh

MAIA Configuration:

Before initiating the script, confirm that your system has Node.js installed. If the script doesn't detect Node.js, it will attempt to install it via Homebrew. In the absence of Homebrew, the script will install Homebrew first and then proceed with the Node.js installation, followed by tmux.

Once Node.js is up and running, the script will automatically handle the installation of the necessary dependencies which include discord.js, dotenv, openai, and nodemon using npm, the Node.js package manager.

During this setup, a .env file is created. This file is crucial as it is where you will enter your configuration settings.

# Discord Settings
DISCORD_TOKEN=
DISCORD_CHANNEL_ID=

Start by entering the Discord token you acquired earlier. If you want MAIA to operate in a specific channel, provide the DISCORD_CHANNEL_ID. Leaving it blank means MAIA can respond in any channel on the server.

# OpenAI Configuration
OPENAI_ORG=
OPENAI_API_KEY=

Input the required values for OpenAI settings. This allows MAIA to communicate with OpenAI and generate responses.

# Chat Log Configuration
CHAT_LOG=0

The CHAT_LOG configuration determines whether MAIA will log the chats. Enabling this can be useful for debugging or monitoring purposes. By default, it's set to '0', which means logging is disabled.


How to Find a Discord Channel's ID

1. Enable Discord Developer Mode

Before you can obtain a Discord channel's ID, the Developer Mode needs to be activated. If you're a Discord bot developer, you might have already turned this on. If not, here's how to do it:

  • Launch Discord and find the settings icon, represented by a cogwheel, at the bottom left of the screen. It's near your avatar and username.

    Discord Settings Icon

  • Click on the icon to open the User Settings.

  • In the left sidebar, select "Advanced" to access the Advanced Settings.

  • In the Advanced Settings, look for the Discord Developer Mode toggle. A green checkmark means it's already enabled. If not, click to turn it on.


2. Find and Copy the Channel ID

  • With Developer Mode on, you're set to obtain the channel's ID.

  • Locate and select the channel whose ID you want to retrieve.

  • On a desktop, right-click the channel name. A menu will pop up with a "Copy ID" option. Selecting this will copy the channel's ID to your clipboard. Refer to the screenshot below for clarity.

  • On mobile, press and hold the channel name until a menu surfaces. From this menu, choose "Copy ID" to copy the channel ID.



Copy Discord Channel ID



With the ID copied, you can use it as needed, like let MAIA know exactly which channel to operate in.


Input Your OpenAI Keys

  1. Identify the Organization ID

  1. Update .env File
  • In your .env file, locate the OPENAI_ORG field.
  • Paste the copied Organization ID.
  • Ensure you've also added the OPENAI_API_KEY you previously obtained.

By following these steps, your .env file will be correctly configured with OpenAI's details.



Deploy MAIA in your Discord server

Once you've set up the bot and keyed in your access details, follow these steps to deploy it, open the terminal, navigate to the MAIA directory, and initiate the bot. You can do this by executing the following command:

maia -s



MAIA Start



If you have set everything up correctly, you'll see the message: "MAIA session started and detached!" This indicates that a new session named "maia_session" has started on tmux, and your bot is now online, ready to function on your Discord server. To view the active tmux sessions, execute the command below:

maia -a



MAIA Deployed



How to use MAIA

Starting and Stopping Session

MAIA is designed to function as a smart assistant within the background of your computing environment. Tmux enhances MAIA's operability by allowing it to run independently in the background. This means you can start MAIA, detach from the tmux session, and continue using your terminal for other tasks while MAIA remains active.

There may be instances where you need to pause MAIA's activity—perhaps for maintenance, updates, or simply to temporarily free up system resources. To manage this, MAIA includes simple-to-use commands that enable you to suspend its session and then, when you're ready, resume operation without having to restart the entire program.

In short, tmux is what gives MAIA the ability to work discreetly and persistently, ensuring your Discord interactions are managed efficiently without monopolising your terminal's workspace.

To start or re-attach to the session:

maia -s

To terminate the session:

maia -k

These commands offer you complete autonomy over MAIA's functionality on your system.

Checking MAIA Session's Status

Post initiation or termination of the MAIA session, it's recommended to verify its status, ensuring its desired operational state:

maia -r

Upon successful execution, a corresponding message will display, showcasing the MAIA session's active or inactive status.



Conclusion

Through the integration of AI chatbots like MAIA, the user experience on Discord can be significantly improved. MAIA, powered by ChatGPT's innovative capabilities, injects vibrancy into your Discord server by delivering valuable and entertaining content to users. These highly sophisticated and appealing AI bots have the potential to boost user interaction and engagement within your Discord communities. By harnessing the power of AI technology through bots like MAIA, you can cultivate a lively, knowledgeable, and captivating atmosphere for all server members.



MAIA Discord Chat



Notes

Resources

Discord

OpenAI

Node.js

Contribution

Thank you for considering the use of this chatbot. Your feedback on improving MAIA would be much appreciated. In case you run into any issues or bugs, please report them on the issues page.

Nicolò Diamante Portfolio

MIT License