# Expired Domain Scraper - Discord Bot

A Discord bot that automatically scrapes expired domains and displays them with the `!ex` command.

## 🌟 Features

- ✅ Automatically scrapes domains at configurable intervals
- ✅ Display domains with `!ex` command
- ✅ Paginated results (20 domains per page)
- ✅ Real-time status updates with `!status`
- ✅ Helpful commands with `!help`
- ✅ Saves to JSON file (optional)
- ✅ Background scraping while bot is running

## 📋 Prerequisites

1. **Node.js** (v16.9.0 or higher)
2. **A Discord Bot Token** - [Get one here](#getting-a-discord-bot-token)

## 🚀 Quick Start

### 1. Install Dependencies
```bash
npm install
```

### 2. Configure the Bot

Edit `config.json` and add your Discord bot token:

```json
{
  "discordToken": "YOUR_DISCORD_BOT_TOKEN_HERE",
  "intervalMinutes": 1,
  "saveToFile": true,
  "outputFile": "domains.json",
  "debug": false,
  "saveRawHtml": false
}
```

### 3. Run the Bot
```bash
npm run bot
```

## 🤖 Getting a Discord Bot Token

1. Go to [Discord Developer Portal](https://discord.com/developers/applications)
2. Click "New Application" and give it a name
3. Go to the "Bot" section in the left sidebar
4. Click "Add Bot"
5. Under the TOKEN section, click "Copy" to copy your bot token
6. Paste it into `config.json` as the `discordToken` value

### 🔗 Invite the Bot to Your Server

1. In the Discord Developer Portal, go to "OAuth2" → "URL Generator"
2. Select the following scopes:
   - ✅ `bot`
3. Select the following bot permissions:
   - ✅ `Send Messages`
   - ✅ `Embed Links`
   - ✅ `Read Message History`
4. Copy the generated URL and open it in your browser
5. Select your server and authorize the bot

## 💬 Bot Commands

| Command | Description | Example |
|---------|-------------|---------|
| `!ex` | Display the latest scraped domains (page 1) | `!ex` |
| `!ex [page]` | Display a specific page of domains | `!ex 2` |
| `!status` | Show bot status and statistics | `!status` |
| `!help` | Display help message | `!help` |

## 📊 Command Examples

### View Latest Domains
```
!ex
```
Shows the first 20 domains from the latest scrape.

### View Specific Page
```
!ex 3
```
Shows domains 41-60 (page 3).

### Check Bot Status
```
!status
```
Shows:
- Bot uptime
- Total number of scrapes performed
- Number of domains found
- Last scrape time
- Scrape interval

## ⚙️ Configuration

Edit `config.json` to customize behavior:

```json
{
  "discordToken": "YOUR_BOT_TOKEN",
  "intervalMinutes": 5,         // Scrape every 5 minutes
  "saveToFile": true,            // Save results to file
  "outputFile": "domains.json",  // Output filename
  "debug": false,                // Enable debug logging
  "saveRawHtml": false          // Save raw HTML for debugging
}
```

### Configuration Options

- **discordToken** (required): Your Discord bot token
- **intervalMinutes**: How often to scrape (in minutes)
- **saveToFile**: Whether to save results to a JSON file
- **outputFile**: Name of the output file
- **debug**: Enable verbose logging for troubleshooting
- **saveRawHtml**: Save raw HTML response for debugging

## 📝 Example Output

When you type `!ex` in Discord:

```
📊 Latest Expired Domains (Scraped 2 minutes ago)
💡 Use !ex 2 to see the next page

🌐 Expired Domains
Recently scraped domains (150 total)

Domains:
1. acheterdrogue.space
2. MooresvilleRent.com
3. NikeAir-Jordan.com
4. vermoxtabs.com
5. nolvadex4world.top
... (15 more)

Page 1/8 | Scrape #42
```

## 🔧 Troubleshooting

### Bot doesn't respond to commands
1. Make sure the bot has "Message Content Intent" enabled in the Discord Developer Portal:
   - Go to your application → Bot → Privileged Gateway Intents
   - Enable "Message Content Intent"
2. Make sure the bot has permission to read and send messages in the channel
3. Check the console for any error messages

### "Invalid Token" error
- Double-check that you copied the entire bot token from the Discord Developer Portal
- Make sure there are no extra spaces in the config.json file

### No domains found
- Enable debug mode: set `"debug": true` in config.json
- Check if the website structure has changed
- The bot will continue trying on each interval

### Bot keeps disconnecting
- Check your internet connection
- Make sure Node.js is up to date (v16.9.0+)
- Check for any error messages in the console

## 🎨 Customization

### Change Domains Per Page
Edit `discord-bot.js` and modify the `perPage` parameter in the `formatDomainsForDiscord` function:

```javascript
function formatDomainsForDiscord(domains, page = 1, perPage = 30) { // Changed from 20 to 30
```

### Change Embed Color
Modify the hex color in the embed creation:

```javascript
.setColor(0xFF0000) // Red instead of blue
```

### Add More Commands
Add new message handlers in the `messageCreate` event:

```javascript
if (message.content === '!mycommand') {
  // Your custom logic here
}
```

## 📦 Files Included

- `discord-bot.js` - Main Discord bot file
- `domain-scraper.js` - Standalone scraper (without Discord)
- `config.json` - Configuration file
- `package.json` - Dependencies
- `README-DISCORD.md` - This file

## 🔒 Security Notes

- **Never share your bot token** - Keep it secret!
- Add `config.json` to `.gitignore` if using version control
- Consider using environment variables for the token in production:
  ```bash
  export DISCORD_TOKEN="your_token_here"
  ```
  Then modify the code to use `process.env.DISCORD_TOKEN`

## 📄 License

MIT

## 🙋 Support

If you encounter any issues:
1. Check the troubleshooting section
2. Enable debug mode to see detailed logs
3. Check the console for error messages
4. Verify your bot token and permissions

## 🌟 Tips

- Set `intervalMinutes` to at least 1-5 minutes to avoid overwhelming the target website
- Use `!status` to monitor how many domains are being found
- The bot will keep running and scraping in the background automatically
- First scrape happens immediately when the bot starts
