Skip to content
This repository was archived by the owner on Feb 27, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ TOKEN=
# What language model to use, orca is one of the lower-end models that doesn't require as much computer power as llama2
MODEL=orca

# Ollama URL (if you want to use multiple, separate them by commas)
# Ollama URL
OLLAMA=http://localhost:11434

# Stable diffusion URL
STABLE_DIFFUSION=http://localhost:7860

# What Discord channels to enable it in (by ID)
CHANNELS=123456789,987654321

Expand Down
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"no-empty": "warn",
"no-empty-function": "error",
"no-floating-decimal": "error",
"no-inline-comments": "error",
"no-lonely-if": "error",
"no-multi-spaces": "error",
"no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1, "maxBOF": 0 }],
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pnpm-lock.yaml
pnpm-lock.yml
node_modules/
.env
.vscode/
52 changes: 30 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,46 @@
<div align="center">
<h1><a href="#"></a>Discord AI Bot</h1>
<h3 align="center"><a href="#"></a>Discord bot to interact with <a href="https://github.com/jmorganca/ollama">Ollama</a> as a chatbot</h3>
<h3><a href="#"></a><img alt="Stars" src="https://img.shields.io/github/stars/mekb-turtle/discord-ai-bot?display_name=tag&style=for-the-badge" /></h3>
<h3><a href="#"></a><img alt="Discord chat with the bot" src="assets/screenshot.png" /></h3>
<h1>Discord AI Bot</h1>
<h2>Repository is now in maintanance mode - rewriting project to Typescript on <a href="https://github.com/238SAMIxD/discord-ai-bot/tree/typescript">typescript</a> branch</h2>
<h3 align="center">Discord bot to interact with <a href="https://github.com/jmorganca/ollama">Ollama</a> and <a href="https://github.com/AUTOMATIC1111/stable-diffusion-webui">AUTOMATIC1111 Stable Diffusion</a> as a chatbot</h3>
<h3><img alt="Stars" src="https://img.shields.io/github/stars/mekb-turtle/discord-ai-bot?display_name=tag&style=for-the-badge" /></h3>
<h3><img alt="Discord chat with the bot" src="assets/screenshot.png" /></h3>
</div>

The project started thanks to [mekb](https://github.com/mekb-turtle).

### Set-up instructions

1. Install [Node.js](https://nodejs.org) (if you have a package manager, use that instead to install this)
- Make sure to install at least v14 of Node.js
- Make sure to install at least v14 of Node.js
2. Install [Ollama](https://github.com/jmorganca/ollama) (ditto)
3. Pull (download) a model, e.g `ollama pull orca` or `ollama pull llama2`
4. Start Ollama by running `ollama serve`
5. [Create a Discord bot](https://discord.com/developers/applications)
- Under Application » Bot
- Enable Message Content Intent
- Enable Server Members Intent (for replacing user mentions with the username)
- Under Application » Bot
- Enable Message Content Intent
- Enable Server Members Intent (for replacing user mentions with the username)
6. Invite the bot to a server
1. Go to Application » OAuth2 » URL Generator
2. Enable `bot`
3. Enable Send Messages, Read Messages/View Channels, and Read Message History
4. Under Generated URL, click Copy and paste the URL in your browser
1. Go to Application » OAuth2 » URL Generator
2. Enable `bot`
3. Enable Send Messages, Read Messages/View Channels, and Read Message History
4. Under Generated URL, click Copy and paste the URL in your browser
7. Rename `.env.example` to `.env` and edit the `.env` file
- You can get the token from Application » Bot » Token, **never share this with anyone**
- Make sure to change the model if you aren't using `orca`
- Ollama URL can be kept the same unless you have changed the port
- You can use multiple Ollama servers at the same time by separating the URLs with commas
- Set the channels to the channel ID, comma separated
1. In Discord, go to User Settings » Advanced, and enable Developer Mode
2. Right click on a channel you want to use, and click Copy Channel ID
- You can edit the system message the bot uses, or disable it entirely
8. Start the bot with `npm start`
9. You can interact with the bot by @mentioning it with your message
- You can get the token from Application » Bot » Token, **never share this with anyone**
- Make sure to change the model if you aren't using `orca`
- Ollama URL can be kept the same unless you have changed the port
- You can use multiple Ollama servers at the same time by separating the URLs with commas
- Set the channels to the channel ID, comma separated
1. In Discord, go to User Settings » Advanced, and enable Developer Mode
2. Right click on a channel you want to use, and click Copy Channel ID
- You can edit the system message the bot uses, or disable it entirely
8. Install the required dependencies with `npm i`
9. Start the bot with `npm start`
10. You can interact with the bot by @mentioning it with your message
11. Install <a href="https://github.com/AUTOMATIC1111/stable-diffusion-webui">Stable Diffusion</a>
12. Run the script `./webui.sh --api --listen`

### Set-up instructions with Docker

1. Install [Docker](https://docs.docker.com/get-docker/)
- Should be atleast compatible with version 3 of compose (docker engine 1.13.0+)
2. Repeat steps 2—7 from the other setup instructions
Expand Down
99 changes: 99 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import globals from "globals";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});

export default [...compat.extends("eslint:recommended"), {
languageOptions: {
globals: {
...globals.node
},

ecmaVersion: 2021,
sourceType: "module"
},

rules: {
"arrow-spacing": ["warn", {
before: true,
after: true
}],

"brace-style": ["error", "1tbs", {
allowSingleLine: true
}],

"comma-dangle": ["error", "never"],
"comma-spacing": "error",
"comma-style": "error",
curly: ["error", "multi-line", "consistent"],
"dot-location": ["error", "property"],
"handle-callback-err": "off",

indent: ["error", "tab", {
SwitchCase: 1
}],

"keyword-spacing": "error",

"max-nested-callbacks": ["error", {
max: 4
}],

"max-statements-per-line": ["error", {
max: 2
}],

"no-console": "off",
"no-empty": "warn",
"no-empty-function": "error",
"no-floating-decimal": "error",
"no-lonely-if": "error",
"no-multi-spaces": "error",

"no-multiple-empty-lines": ["error", {
max: 2,
maxEOF: 1,
maxBOF: 0
}],

"no-shadow": ["error", {
allow: ["err", "resolve", "reject"]
}],

"no-trailing-spaces": ["error"],
"no-var": "error",
"object-curly-spacing": ["error", "always"],
"prefer-const": "error",
quotes: ["error", "double"],
semi: ["error", "always"],
"space-before-blocks": "error",

"space-before-function-paren": ["error", {
anonymous: "never",
named: "never",
asyncArrow: "always"
}],

"space-in-parens": "error",
"space-infix-ops": "error",
"space-unary-ops": "error",
"spaced-comment": "error",
yoda: "error",
"default-case-last": "error",

"switch-colon-spacing": ["error", {
after: true,
before: false
}]
}
}];
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@
"dotenv": "^16.3.1",
"meklog": "^1.0.2"
},
"type": "module"
"type": "module",
"devDependencies": {
"@eslint/js": "^9.7.0",
"@types/eslint__js": "^8.42.3",
"eslint": "^9.7.0",
"globals": "^15.8.0"
}
}
Loading