No description
- Python 96.9%
- Dockerfile 3.1%
| .env.example | ||
| .gitignore | ||
| bot.py | ||
| bot_utilities.py | ||
| docker-compose.yml | ||
| Dockerfile | ||
| README.md | ||
| requirements.txt | ||
| sherpaAI.py | ||
Discord Bot with Image Storage and Persistent Folder
This project is a simple Discord bot built with discord.py that can save image attachments from Discord messages to a persistent folder and list saved images on command. The bot runs inside a Docker container, and a host folder is mounted into the container to store the images, allowing you to access them outside the container as well.
Features
- Saves image attachments (
.png,.jpg,.jpeg,.gif) sent to the bot in Discord. - Lists all saved images when the
!listimagescommand is sent. - Stores images in a persistent
imagesfolder bind-mounted from the host machine. - Runs inside a Docker container for easy deployment and isolation.
Project Structure
discord-bot/
├── bot.py # The bot source code
├── Dockerfile # Docker image build instructions
├── docker-compose.yml # Compose file to run the container and mount volumes
├── requirements.txt # Python dependencies
├── .env # Environment variables (Discord bot token)
└── images/ # Host folder mounted inside container to persist images
Setup Instructions
1. Clone the Repository
git clone <repository-url>
cd discord-bot
2. Create Discord Bot and Get Token
- Follow Discord developer docs to create a bot application and invite it to your server.
- Copy the bot token.
3. Create .env File
Create a .env file in the project root and add your bot token:
DISCORD_TOKEN=your_bot_token_here
4. Create the Images Folder
Create an images folder in the project root to store the images:
mkdir images
5. Build and Run the Docker Container
Build the Docker image and run the container using Docker Compose:
docker compose up --build
The bot should now connect to Discord.
How It Works
- Image saving: When the bot receives a message with image attachments, it saves each image file inside the
/app/imagesdirectory in the container. - Persistent storage: The
/app/imagesfolder is volume-mounted to theimagesfolder on your host machine, which means all saved images persist on your computer outside the container. - Image listing: On receiving the
!listimagescommand, the bot lists all image filenames saved in the images folder. - Environment variables: The bot retrieves the Discord token via environment variables loaded from the
.envfile injected into the container.
Usage
- Invite the bot to your Discord server.
- Send a message with image attachments to any channel the bot can read.
- The bot will confirm saving each image.
- Send
!listimagesin a channel to get a list of all saved images.
Stopping the Bot
To stop the bot and remove the container, run:
docker compose down
Notes
- Ensure the bot has permissions to read and send messages in your Discord server.
- The bind mount syncs the
imagesfolder on your host with the container, allowing manual file management if needed. - You can add extra commands or extend functionality by modifying
bot.pyand rebuilding the image.
Feel free to open issues or request features!