# Discord Message Scraper (`harvestedge/discord-message-scraper`) Actor

Scrape Discord messages effortlessly with this Apify actor. Extract channel data, attachments, and embeds with customizable settings. Try now!

- **URL**: https://apify.com/harvestedge/discord-message-scraper.md
- **Developed by:** [Harvest Edge](https://apify.com/harvestedge) (community)
- **Categories:** Social media, Lead generation, SEO tools
- **Stats:** 10 total users, 0 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-usage

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

🌽🌽🌽🌽🌽🌽🌽🌽🌽🌽🌽🌽🌽🌽🌽🚜

🌽🌽🌽🌽🌽🌽🌽🌽🌽🌽🌽🌽🌽🌽🌽🌽

## Harvest Edge / Discord Message Scraper

🌱🌱🌱🌱🌱🌱🌱🌱🌱🌱🌱🌱🌱🌱🌱🌱

🌽🌽🌽🌽🍆🌽🌽🌽🌽🚜🌱🌱🌱🌱🌱🌱

Harvest Edge makes business information available to everyone!

### Overview

Easily scrape Discord messages with the Discord Message Scraper, a powerful Apify actor designed for developers and data analysts. This actor extracts messages, attachments, embeds, reactions, and mentions from any Discord channel or guild, using the Discord API. With support for scraping in both “newer” and “older” directions and a customizable 60-second timeout, it ensures reliable data collection for analytics, research, or archiving.
Feel free to contact us via Apify for feature requests or bug reports.

### How to Get Your Token

- Open **developer tools** on your browser, by pressing F12, and go to discord.com/channels/@me
- Click the 'Network' tab in the developer tools, and find the file named **@me**. You can filter for Fetch/XHR requests to help find it. Refresh the page if you do not see it.
- Be sure you are looking at the 'Headers' of this file and scroll down to **'Request Headers'**
- Your token is the code that is listed as **'Authorization'**

### Features

- Fetches up to 10,000 messages per run from a specified Discord channel.
- Supports scraping in batches, with the option of going either direction from a starting message.
- Outputs detailed message data (content, author, timestamp, attachments, embeds, etc.) to an Apify dataset.
- Configurable batch delay to manage Discord API rate limits.
- Robust error handling with clear logs for troubleshooting.

## Performance

- **Execution Time**: Fetching 1000 messages takes ~10 seconds (with default 1.0-second batch delay). Fetching the maximum 10,000 messages takes ~100 seconds (~1.7 minutes).
- **Resource Usage**: Optimized for low compute unit consumption, with a maximum limit of 10,000 messages to prevent excessive resource use.

## Input

The Actor accepts the following input parameters via the Apify platform:

| Key                     | Type   | Description                                                                                                                  | Default                     | Required |
|-------------------------|--------|------------------------------------------------------------------------------------------------------------------------------|-----------------------------|----------|
| `guild_id`              | String | The ID of the Discord guild (server) containing the channel.                                                                 | -                           | Yes      |
| `channel_id`            | String | The ID of the Discord channel to fetch messages from.                                                                        | -                           | Yes      |
| `token`                 | String | Your Discord user account token for authentication. Ensure compliance with Discord's Terms of Service.                       | -                           | Yes      |
| `max_messages`          | Integer| Limit the number of messages to fetch (1 to 10,000). Use 100 for quick tests or up to 10,000 for large channels.             | 1000                        | No       |
| `start_message_id`      | String | Message ID to start scraping from. For "newer", scrapes messages before this ID; for "older", scrapes messages after this ID.| -                           | No       |
| `scrape_direction`      | String | Direction to scrape: "newer" (towards past) or "older" (towards future).                                                     | Newer                       | No       |
| `batch_delay_seconds`   | String | Delay between batches of 100 messages (non-negative number, in seconds). Increase to 2.0 if rate limit errors occur.         | 1.0                         | No       |

### Output

The Actor outputs a dataset in JSON format with the following fields for each product:

| Field              | Description                                        |
|--------------------|----------------------------------------------------|
| `guild_id`         |  Unique ID of the message.                         |
| `channel_id`       |  ID of the channel.                                |
| `author`           |  Object with author details (ID, username, discriminator, avatar, public flags).      |
| `content`          |  Message text content.                             |
| `timestamp`        |  Creation timestamp (YYYY-MM-DD HH:MM:SS).         |
| `edited_timestamp` |  Edit timestamp, if edited (YYYY-MM-DD HH:MM:SS).  |
| `type`             |  Message type (e.g., default, reply).              |
| `attachments`      |  Array of attachment objects (ID, filename, size, URL, etc.).   |
| `embeds`           |  Array of embed objects (type, URL, title, description, etc.).  |
| `pinned`           |  Boolean indicating if the message is pinned.      |
| `mention_everyone` |  Boolean indicating if the message mentions everyone.   |
| `tts`              |  Boolean indicating if the message is text-to-speech.   |
| `flags`            |  Message flags (integer).                          |
| `components`       |  Array of message components (e.g., buttons).      |
| `reactions`        |  Array of reaction objects (emoji, count, etc.).   |
| `mentions`         |  Array of mentioned user objects (ID, username, discriminator).   |
| `message_reference`|  Object with reply details (message ID, channel ID, guild ID), if a reply.   |

**Example Output**:

```json
{
  "message_id": "123456789012345678",
  "channel_id": "987654321098765432",
  "author": {
    "id": "111222333444555666",
    "username": "user",
    "discriminator": "1234",
    "avatar": "https://cdn.discordapp.com/avatars/...",
    "public_flags": 0
  },
  "content": "Hello, world!",
  "timestamp": "2025-10-08 14:30:00",
  "edited_timestamp": null,
  "type": 0,
  "attachments": [],
  "embeds": [],
  "pinned": false,
  "mention_everyone": false,
  "tts": false,
  "flags": 0,
  "components": [],
  "reactions": [],
  "mentions": [],
  "message_reference": null
}
```

### Troubleshooting

- **Invalid Token**: Ensure the token is correct and not expired. Obtain a new token if needed.
- **Message ID Not Found**: Verify the start_message_id exists in the specified channel and is accessible.
- **Rate Limit Errors**: Increase batch_delay_seconds to 2.0 or higher if you see HTTPException errors.
- **Timeout Errors**: If the Actor times out after 60 seconds while fetching the starting message, check the start_message_id and network connection, or contact support for assistance.
- **No Messages Fetched**: Ensure the channel has messages and the token has permission to read the channel’s history.

# Actor input Schema

## `guild_id` (type: `string`):

The ID of the Discord guild (server) containing the channel.

## `channel_id` (type: `string`):

The ID of the Discord channel to fetch messages from.

## `token` (type: `string`):

Your Discord user account token for authentication. Ensure compliance with Discord's Terms of Service (https://discord.com/terms). Automated scraping may violate Discord's policies if misused.

## `max_messages` (type: `integer`):

Limit the number of messages to fetch (default: 1000, maximum: 10000). Use 100 for quick tests or up to 10000 for large channels. For more messages, run multiple times with different Start Message IDs.

## `start_message_id` (type: `string`):

Message ID to start scraping from (optional). For 'newer', scrapes messages before this ID; for 'older', scrapes messages after this ID.

## `scrape_direction` (type: `string`):

Direction to scrape messages: 'newer' (default, towards past) or 'older' (towards future).

## `batch_delay_seconds` (type: `string`):

Delay between batches of 100 messages (default: 1.0 seconds). Must be a non-negative number.

## Actor input object example

```json
{
  "max_messages": 1000,
  "scrape_direction": "newer",
  "batch_delay_seconds": "1.0"
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("harvestedge/discord-message-scraper").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("harvestedge/discord-message-scraper").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call harvestedge/discord-message-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,harvestedge/discord-message-scraper"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/KnIEobq1ckv3qoon3/builds/GpNGFJhlDM7Nsyjqr/openapi.json
