This AI-powered chatbot uses discord.js and the LM Studio sdk to allow a Large Language Model to communicate with users on Discord.
To run this project, you will need to have Node.js installed on your machine. You can download it from the official website: https://nodejs.org/en/download/
Additionally you will need to install the necessary dependencies by running the following command in your terminal:
npm install
To configure the bot, you will need to create a .env file in the root directory of the project and add the following environment variables:
APP_ID=your-discord-app-id
DISCORD_TOKEN=your-discord-bot-token
SERVER_ID=your-development-server-id
AI_MODEL=AI-model-api-identifier-from-LMStudio-developer-tab
# Optional Variables
SYSTEM_PROMPT="optional-prompt-to-determine-AI-goals-and-personality"
KEYWORDS=optional, list, of, keywords, to, trigger, bot
PROMPT_EVASION_DETECTION=true/false
PROMPT_EVASION_DETECTION_MESSAGE=Nice try.
BOT_DETECTION=true/false
BOT_DETECTION_MESSAGE=I am not a bot!
You can find your Discord bot token and app ID by following these steps:
- Go to the Discord Developer Portal: https://discord.com/developers/applications
- Click on the "New Application" button.
- Give your application a name and click on the "Create" button.
- Click on the "Bot" tab on the left-hand side of the page.
- Click on the "Add Bot" button.
- Click on the "Copy" button next to the "Token" field.
- Paste the token into the .env file as the value of the DISCORD_TOKEN environment variable.
- Navigate to your bot's General Information tab
- Copy the Application ID and paste it into the .env file as the value of the APP_ID environment variable.
You can find your Discord server's ID by right clicking on the server's name and clicking copy ID. You will need developer mode to be on in Discord's settings under App Settings/Advanced.
You will also need to install LM Studio and create a model. You can get LM Studio here: https://lmstudio.ai/
In LM Studio you can find and download models using the Discover tab. Once LM Studio is set up follow these steps:
- Ensure you are in Developer mode.
- Run the server from the Developer tab.
- Select a model to load.
- Copy the model name from the loaded model or the info side panel and paste it into .env file as the value of the AI_MODEL environment variable.
Once you have installed the dependencies, you can deploy the commands by running:
node deploy-commands
By default the commands will deploy to one server, as this is quicker. The server will be defined in your .env file. See Configuration for more information.
To deploy commands globally, run this command instead:
node deploy-commands --global
Or:
node deploy-commands -G
It can take up to an hour or more for global commands to appear in Discord.
There are three arguments the deploy-commands script can be run with:
-g / --guild //Force deploys to guild
-G / --global //Force deploys globally
-p / --preserve //Preserves previously existing scripts, useful for keeping guild commands while deploying globally
Once the commands are deployed, run the bot with:
node index
Once the bot is running, you can interact with it by sending messages in a Discord channel that the bot has access to. The bot will respond to your messages with a response generated by the LM Studio model.
This bot includes a /elite_community_goals
command that fetches current community goals from the Elite Dangerous universe using the Inara API.
To use this feature, you'll need to register for API access on the Inara website:
- Create an account on Inara if you don't already have one
- Apply for API access through their developer portal and carefully follow the API dev instructions
- Once approved, you'll receive an API key and your app will be whitelisted
Add the following variables to your .env
file:
INARA_APP_NAME=App name you gave to Inara creator
INARA_APP_VERSION=Version of your application
INARA_API_KEY=inara-api-key
INARA_COMMANDER_NAME=elite-dangerous-username
INARA_COMMANDER_FRONTIER_ID=frontierID
Once configured, users can use the /elite_community_goals
command in Discord to see active community goals in Elite Dangerous. The command displays:
- Goal names and locations
- Time remaining
- Objective descriptions
- Progress information
- Average contribution amount
The data is cached for 4 hours to prevent excessive API requests.