{"id":20063683,"url":"https://github.com/ausboss/dbotjs","last_synced_at":"2026-04-17T09:32:35.296Z","repository":{"id":231117804,"uuid":"780957948","full_name":"ausboss/dbotjs","owner":"ausboss","description":"A Discordjs bot that uses OpenAI compatible endpoints for chatting.","archived":false,"fork":false,"pushed_at":"2024-08-07T17:25:18.000Z","size":261,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-14T14:57:03.868Z","etag":null,"topics":["discord-bot","discordjs","discordjs-bot","llm","openai-api","openai-compatible-api","tabby-api","text-generation-webui"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ausboss.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-02T13:37:46.000Z","updated_at":"2024-07-05T14:02:38.000Z","dependencies_parsed_at":"2024-05-20T22:38:48.273Z","dependency_job_id":"8555c299-7101-439a-a56a-908376d18e31","html_url":"https://github.com/ausboss/dbotjs","commit_stats":null,"previous_names":["ausboss/dbotjs"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ausboss/dbotjs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ausboss%2Fdbotjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ausboss%2Fdbotjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ausboss%2Fdbotjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ausboss%2Fdbotjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ausboss","download_url":"https://codeload.github.com/ausboss/dbotjs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ausboss%2Fdbotjs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31923153,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-17T09:10:15.403Z","status":"ssl_error","status_checked_at":"2026-04-17T09:10:14.455Z","response_time":62,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["discord-bot","discordjs","discordjs-bot","llm","openai-api","openai-compatible-api","tabby-api","text-generation-webui"],"created_at":"2024-11-13T13:43:28.811Z","updated_at":"2026-04-17T09:32:35.278Z","avatar_url":"https://github.com/ausboss.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Bot Configuration\n\n---\n\n## Quick Start Guide\n\n\n### Step 1: Install Dependencies\n\nFirst, install the necessary packages with npm:\n\n```bash\nnpm install\n```\n\n### Step 2: Configure Environment\n\nSet up your environment variables for secure access to Discord and OpenAI:\n\n- **Rename `.env` File**:  \n  Copy or rename the `example.env` to `.env`.\n\n- **Set Bot Token**:  \n  Open the `.env` file and insert your Discord bot token next to `BOT_TOKEN`.\n\n    ```plaintext\n    BOT_TOKEN=your_discord_bot_token_here\n    ```\n\n- **Set OpenAI API Key** (Optional):  \n  If you're using OpenAI, add your API key to the same `.env` file.\n\n    ```plaintext\n    OPENAI_API_KEY=your_openai_api_key_here\n    ```\n\n### Step 3: Configure Bot Settings\n\nAdjust your bot's behavior and AI settings:\n\n- **Rename `config.json` File**:  \n  Copy or rename the `example-config.json` to `config.json`.\n\n- **Customize Settings**:  \n  Edit `config.json` to include the channel IDs to listen on and pass in your custom endpoint or leave out to use `https://api.openai.com/v1`\n\n    ```json\n    {\n      \"llmBaseUrl\": \"http://127.0.0.1:5000/v1\",\n      \"channelIds\": [\"1234567891011121314\", \"1234567891011121314\"],\n      \"openAIConfig\": {\n        \"stop\": [\"\\n\"]\n      },\n      \"ignorePatterns\": [\".\", \"!\"]\n    }\n    ```\n\n### Step 4: Start the Bot\n\nLaunch your bot with the following command. (Tested on Node.js version 20.9.0):\n\n```bash\nnpm run dev\n```\n\n---\n\n# More Details\n\n---\n\n## `.env` Setup\n\nFor basic functionality, store your Discord bot token:\n\n```\nBOT_TOKEN=YOUR_BOT_TOKEN\n```\n\nIf using OpenAI add:\n\n```\nOPENAI_API_KEY=YOUR_OPENAI_API_KEY\n```\n\n\nThis application is designed to work seamlessly with most OpenAI-compatible APIs. It allows users to specify any parameters supported by their selected endpoint.\n\n##  `config.json` Setup\n\nYour `config.json` enables direct, detailed customization for API calls. It supports most parameters for OpenAI and OpenAI-compatible endpoints. This includes, but is not limited to, parameters documented for OpenAI and similar services.\n\n### Configuration Structure\n\n```json\n{\n  \"llmBaseUrl\": \"http://127.0.0.1:5000/v1\",\n  \"channelIds\": [\"1148253350404575352\", \"1153875844251529338\"],\n  \"openAIConfig\": {\n    \"maxTokens\": 200,\n    \"stop\": [\"\\n\"]\n    // Specify any parameters supported by your endpoint\n  },\n  \"ignorePatterns\": [\".\", \"!\", \"/\"],\n  \"K\": 15\n}\n\n```\n\n- **llmBaseUrl**: Leave blank if using openai. If you are using something like Tabby or Oobabooga then you would put in the endpoint address followed by /v1. \n- **channelIds**: Specifies which Discord channels the bot will listen to and reply within. Only messages from these channels will be processed.\n\n- **openAIConfig**: Contains parameters for the API requests, allowing for detailed customization of the language model's behavior.\n  - `maxTokens`, `temperature`, `topP`, `minP`, `repetitionPenalty` are among the customizable parameters to tailor the AI's responses.\n  - `stop`: An array of tokens that signal the language model to stop generating further text. Useful for defining clear end-points in generated content.\n\n- **ignorePatterns**: Defines patterns (typically starting characters) that the bot will ignore. Messages starting with any characters or strings listed here will not trigger a response. Useful for filtering out commands or other bot interactions.\n- **K**: The number of last K interactions to keep in the history context. This can be useful for keeping a sliding window of the most recent interactions, so the buffer does not get too large.\n\n### Supported Parameters\n\nFor those using the OpenAI endpoint, you can specify a wide range of parameters to tailor the API's behavior to your needs. These parameters include, but are not limited to:\n- Model selection (`model`)\n- Maximum token count (`maxTokens`)\n- Temperature for randomness control (`temperature`)\n\nA comprehensive list of the langchain.js supported parameters and their functions can be found in the [OpenAI documentation](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.openai.OpenAI.html#langchain_community.llms.openai.OpenAI).\n\n### Example Configuration\n\n```json\n{\n  \"llmBaseUrl\": \"http://127.0.0.1:5000/v1\",\n  \"openAIConfig\": {\n    \"maxTokens\": 100,\n    \"temperature\": 0.7\n    // Additional parameters as needed\n  }\n}\n```\n\n### Security and Flexibility\n\nSensitive information, such as API keys or BOT Tokens, should be managed through environment variables to maintain security. The `config.json` file is intended for non-sensitive configurations, allowing for easy adjustments without code changes.\n\n\nCertainly! Let's adjust the explanation for a group chat scenario and mention the use of an SQL database for message history:\n\n---\n\n## Dynamic Prompt Construction with `prompt.txt`\n\nIn our bot's architecture, the `prompt.txt` file is a pivotal element for creating dynamic, context-aware prompts that the bot sends to the language learning model (LLM). This mechanism is especially crucial for group chat interactions, where context and continuity play significant roles in generating relevant responses.\n\n### How `prompt.txt` Works\n\n`prompt.txt` serves as a template that includes placeholders for dynamically inserting content. These placeholders include the bot’s display name (`{{char}}`), the name of the user sending the message (`{{user}}`), and the recent chat history (`{{history}}`). This approach allows for personalized and context-rich interactions with the LLM.\n\n### Group Chat Example\n\nConsider a group chat where multiple users interact, and the bot, named \"AidBot,\" participates. Here's how a `prompt.txt` might be structured:\n\n```\nYou are a helpful assistant named {{char}}.\n{{history}}\n```\n\n### From Template to Contextual Prompt\n\nWhen preparing a prompt for the LLM, the bot replaces placeholders with actual data:\n\n- `{{char}}` becomes \"AidBot.\"\n- `{{history}}` is filled with the last 10 messages from the group chat, as stored in the SQL database. This inclusion is crucial as it provides the LLM with the necessary context to generate coherent and contextually appropriate responses.\n\n#### Example of a Formatted Prompt\n\nGiven a series of interactions in a group chat, the formatted prompt might look as follows:\n\n```\nYou are a helpful assistant named AidBot.\nAlex: Does anyone remember the capital of France?\nJordan: It's Paris, right?\nAlex: Yes, thanks! AidBot, can you list all the countries in the EU?\nAidBot: Sure, the EU consists of...\nKim: AidBot, what's the weather like in Paris today?\nAidBot:\n```\n\n### Incorporating SQL Database for Message History\n\nThe bot's ability to insert the recent chat history into each prompt relies on pulling data from an SQL database where all messages are logged. This setup ensures that even in dynamic and fast-paced group chats, the bot remains contextually aware and provides responses that reflect the ongoing conversation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fausboss%2Fdbotjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fausboss%2Fdbotjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fausboss%2Fdbotjs/lists"}