A professional Discord bot that automatically fetches and uploads profile pictures (PFPs), banners, and GIFs from Pinterest API to Discord channels. Built with Node.js, TypeScript, Discord.js, and Pinterest API integration.
- 🔍 Smart Media Search: Search Pinterest for specific types of media (PFPs, banners, GIFs)
- 📥 Automatic Downloads: Automatically downloads and processes media from Pinterest
- 🚀 Discord Integration: Seamlessly uploads media to Discord channels with rich embeds
- ⚡ Async Event Handling: Efficient asynchronous processing for optimal performance
- 🎯 Command System: Easy-to-use slash-style commands for fetching media
- 🔒 Type-Safe: Built with TypeScript for type safety and better developer experience
- 🛡️ Rate Limit Protection: Built-in rate limiting for both Discord and Pinterest API
- 💾 Database Caching: Prisma-powered caching to reduce API calls and improve performance
- 📊 Usage Tracking: Logs all command usage for analytics and debugging
- Node.js - Runtime environment
- TypeScript - Type-safe JavaScript
- Discord.js - Discord API wrapper
- Prisma - Database ORM with SQLite
- Axios - HTTP client for API requests
- Pinterest API - Media source
- p-queue - Queue management for rate limiting
- Node.js 18.0.0 or higher
- npm or yarn package manager
- Discord Bot Token
- Pinterest API Access Token
- SQLite (included with Node.js)
-
Clone the repository
git clone https://github.com/yourusername/pinterest-discord-bot.git cd pinterest-discord-bot -
Install dependencies
npm install
-
Configure environment variables
cp .env.example .env
Edit
.envand fill in your credentials:DISCORD_TOKEN=your_discord_bot_token_here DISCORD_CLIENT_ID=your_discord_client_id_here PINTEREST_ACCESS_TOKEN=your_pinterest_access_token_here PREFIX=! DATABASE_URL=file:./data.db RATE_LIMIT_MAX_REQUESTS=10 RATE_LIMIT_WINDOW_MS=60000
-
Set up Prisma database
npm run prisma:generate npm run prisma:migrate
-
Build the project
npm run build
-
Start the bot
npm start
For development with auto-reload:
npm run dev
- Go to Discord Developer Portal
- Create a new application
- Go to the "Bot" section
- Create a bot and copy the token
- Enable the following intents:
- Message Content Intent
- Server Members Intent (if needed)
- Go to Pinterest Developers
- Create a new app
- Generate an access token with appropriate permissions
- Copy the access token to your
.envfile
Once the bot is running, you can use the following commands in your Discord server:
-
!pfp <query>- Fetches profile pictures from Pinterest- Example:
!pfp anime character
- Example:
-
!banner <query>- Fetches banners/headers from Pinterest- Example:
!banner gaming
- Example:
-
!gif <query>- Fetches GIFs from Pinterest- Example:
!gif funny cat
- Example:
-
!pin <pin_id>- Fetches a specific pin by ID- Example:
!pin 1234567890
- Example:
-
!help- Shows available commands
!pfp cyberpunk
!banner landscape
!gif reaction
!pin 9876543210
pinterest-discord-bot/
├── src/
│ ├── handlers/
│ │ ├── command.handler.ts # Command processing logic
│ │ └── event.handler.ts # Discord event handlers
│ ├── services/
│ │ ├── pinterest.service.ts # Pinterest API integration
│ │ └── media-fetcher.service.ts # Media fetching and processing
│ └── index.ts # Main entry point
├── dist/ # Compiled JavaScript (generated)
├── .env.example # Environment variables template
├── .gitignore
├── package.json
├── tsconfig.json
└── README.md
-
PinterestService: Handles all interactions with the Pinterest API, including search, pin retrieval, and media parsing.
-
MediaFetcherService: Manages downloading media from URLs, creating Discord attachments, and generating embeds.
-
CommandHandler: Processes Discord commands, validates input, and executes appropriate actions.
-
EventHandler: Registers and manages Discord bot events (ready, message create, errors, etc.).
npm run build- Compile TypeScript to JavaScriptnpm start- Run the compiled botnpm run dev- Run bot with ts-node (development)npm run watch- Watch mode for TypeScript compilationnpm run prisma:generate- Generate Prisma clientnpm run prisma:migrate- Run database migrationsnpm run prisma:studio- Open Prisma Studio (database GUI)
This project follows TypeScript best practices:
- Strict type checking
- ES2022 target
- Comprehensive error handling
- Async/await for asynchronous operations
The bot includes comprehensive error handling:
- API request failures are caught and reported to users
- Invalid commands show helpful error messages
- Network timeouts are handled gracefully
- Media download failures don't crash the bot
- Maximum 5 media items per command (to prevent rate limiting)
- 25MB file size limit for downloads
- Pinterest API rate limits apply
- Discord file size limits (8MB for regular users, 25MB for Nitro)
Contributions are welcome! Please feel free to submit a Pull Request.
MIT License - feel free to use this project for your own purposes.
For issues, questions, or contributions, please open an issue on GitHub.
Built with ❤️ using Node.js, TypeScript, and Discord.js