This repository contains two components: a **Discord bot** for shortening URLs and a **backend API** for handling the URL shortening and redirection. Both parts work together to provide a seamless experience for shortening URLs and sharing them directly from Discord.
## Features
- **Discord Slash Command** for URL shortening with domain selection.
- **Express.js Backend API** to handle the actual shortening process and redirection.
- **MongoDB Integration** for storing and retrieving shortened URLs.
- **API Key Validation** for secure access to the backend.
## Components
### 1. `short.js` - Discord URL Shortener Bot
This is a Discord bot built using `discord.js` that provides a command to shorten URLs directly from Discord. Users can choose from multiple domains, or the bot will use a default domain.
#### Setup Instructions for `short.js`
1.**Install dependencies**:
```bash
npm install discord.js unirest dotenv
```
2.**Environment Variables**:
Create a `.env` file in the project root and add:
```
BOT_TOKEN=your_discord_bot_token
DISCORD_CLIENT_ID=your_discord_client_id
API_KEY=your_url_shortening_api_key
```
3.**Run the bot**:
```bash
node short.js
```
#### How It Works
- Users enter a URL and optionally choose a domain using the `/shortenurl` slash command.
- The bot validates the URL and sends a request to the backend API to generate the shortened link.
- The response is sent back as a Discord embed message with the shortened URL.
This is a Node.js backend API using `Express.js` and `MongoDB` for URL shortening. It receives requests from the Discord bot or any client and provides a short URL in response.
#### Setup Instructions for `short-backend-api.js`
1.**Install dependencies**:
```bash
npm install express mongoose shortid dotenv
```
2.**MongoDB Setup**:
Make sure MongoDB is running and accessible. By default, it connects to `mongodb://127.0.0.1:27017/shorturl`.