An AI-powered accessibility Discord bot written in Node.js, using Discord.js, MongoDB and Google Gemini API.
The image-reader bot is designed to describe and transcribe images for the visually impaired, features a manual image-reading command and an auto-reading system that automatically provides descriptions for all images sent in a designated channel.
The selevant files in the src folder:
- commands/ - Slash and context command declarations:
- context/prompt.js - The "Set prompt" message context menu command.
- regular/ - Commands accessible to all users:
- bot.js - Global commands: Bot's description, ping and command list. (from template)
- checkChat.js - The
/check-chatcommand. - readImage.js - The
/read-imagecommand.
- serverLocked/ - Commands that register only in certain servers:
- homeGuild/manage.js - The
/managebot owner commands, register only in the testing server. (from template)
- homeGuild/manage.js - The
- staff/ - Admin and mod commands:
- chat.js - The
/chatcommands: Add/Remove auto-reading. (admin only) - chatsList.js - The
/chats-listcommand. - prompt.js - The
/promptcommand: Edit auto-reading prompt.
- chat.js - The
- config/info.json - User-facing messages and default display values, contains the
system instructionsanddefault prompt. - events/client/messageCreate.js - Handles plain message commands and images sent in auto-reading channels.
- functions/
- commands/ - The logic of the commands declared in
src/commands. - runtime/ - Functions used during runtime:
- services/chatService.js - Functions managing the auto-reading channel database operations.
- commands/ - The logic of the commands declared in
- schemas/ - MongoDB schemas:
- access.js - Defines the IDs of the bot's owner and testing server. (from template)
- chat.js - Structure for saving auto-reading channels and their custom prompts.
- profile.js - Additional data about the bot: testing/main, presence and log-channel, get created automatically. (from template)
- app.js - The app's bootstrapper. (from template)
- index.js - The app's entry point. (from template)
Note
Other folders and files come from my Modular Discord.js Bot Template.
See the repo for in-depth documentation.
- Node.js 22.14.0
- npm 10.1.0
The app may work with other versions, but these are the versions that were used during development.
Note
For a more in-depth explanation covering Discord permissions, environment setup and app flags, see the template's installation process.
- Create a new application in the Discord Developers Portal if you don't already have one.
- Get your API key from the Google AI Studio (Gemini Developer Portal).
- Open a MongoDB project if you don't already have one.
- Create a
.envfile in the root directory of the project and fill it with the following:
TOKEN=<Discord bot token>
API_KEY=<Gemini API key>
DBURL=mongodb+srv://<USERNAME>:<PASSWORD>@<CLUSTER>.mongodb.net/<DATABASE>?retryWrites=true&w=majority- Create a document in your MongoDB database according to the schema in
access.js, for example:
"IDs": [
{
"label": "OWNER_ID",
"value": "<Bot's owner Discord user ID>",
"roles": [ "owner"],
"idType": "user"
},
{
"label": "HOME_GUILD",
"value": "<Bot's testing Discord server ID>",
"roles": [ "homeGuild" ],
"idType": "guild"
},
],
"Aliases": [
{ "label": "<Discord server ID>", "value": "<alias for the server name>" }
]Note
Aliases are optional but useful for servers with long or unusual names that might clutter the logs.
- Run
npm ito install all dependencies. - Start
node src/index.jsusingnode .ornpm start.
Check if auto-reading is enabled in a channel and what prompt will be used.
Arguments:
- channel: The channel to check, if none specified will check the current channel.
- type:
Text channel
- type:
Note
Plain message version: check-chat(#channel)
Read and describe the provided image(s).
Note
Plain message version: read-image(prompt) & attach at least one image.
Arguments:
- image1: An image to read.
- type:
Attachment - jpeg / png / webp|required
- type:
- image2-10: Additional images to read (up to 9 more).
- type:
Attachment - jpeg / png / webp
- type:
- prompt: Specific questions about the image(s) or the response's format.
- type:
Text
- type:
Add auto-reading in a channel.
Arguments:
- channel: Where to add up auto-reading, if none specified will pick the current channel.
- type:
Text channel
- type:
- prompt: A custom prompt for the bot to use that this channel.
- type:
Text
- type:
Note
Plain message version: chat.add(#channel, prompt)
Remove auto-reading from a channel.
Arguments:
- channel: Where to remove auto-reading, if none specified will pick the current channel.
- type:
Text channel
- type:
Note
Plain message version: chat.remove(#channel)
Stop auto-reading in all channels in the server.
Note
Plain message version: chat.remove-all()
Provides a list of all channels where the bot is currently set up for auto-reading.
Note
Plain message version: chats-list()
Edit a channel's custom prompt.
Arguments:
- channel: The channel to edit, if none specified will edit the current channel's prompt.
- type:
Text channel
- type:
- prompt: Custom prompt for the channel, leave empty to remove prompt.
- type:
Text
- type:
Note
Plain message version: chat.prompt(#channel, prompt)
Edit a channel's custom prompt using an existing message's content.
To use, right-click or long-tap a message with the desired prompt -> Apps -> Set prompt.
Note
For an in-depth explanation of the template's built in commands and how to use them via plain message command calls, see the template's Built-in Commands and Components.
/bot about- Provides the bot's "about" description./bot commands- Provides descriptions of the bot's commands. Optionally, accepts the name of a category./bot ping- Provides the bot's ping and performs a simple permissions check (response changes based on whether the owner ran the command).
/manage commands loaded- View the currently loaded commands./manage commands reload- Reload bot's commands. (once in 10 minutes)/manage log-channel check- Check the current log channel./manage log-channel update- Update bot's log channel./manage presence- Update bot's presence, leave all empty to reload from database./manage reload-database- Reload information from database./manage state- Update bot's state (allows to disable bot responses by putting it insleepmode).
- Use the
/read-imagecommand to manually send images and receive a description or transcription. - Server admins can set up the auto-reading feature in specific channels using
/chat addand adjust reading instructions using/prompt. - Use the
/check-chatcommand to verify if a channel has auto-reading enabled and view its current prompt.
Important
The bot is configured to process only one image-reading request at a time.
If you are deploying this bot for a large user base and prioritize performance over potentially higher API costs, you can remove the busy boolean check in src/functions/commands/regular/readImage.js.
Caution
In case of misuse or a significant spike in traffic, you can quickly disable all bot activity:
Use the command /manage state and set the state to "sleep".
(To resume activity use the command again and set it to "active")