# Discord Message Sentiment (`harvestedge/discord-message-sentiment`) Actor

The Discord Message Sentiment Scraper collects message data — including text, embeds, attachments, reactions, and mentions — from any channel and performs real-time sentiment analysis. Perfect for lead generation, data analysis, and marketing.

- **URL**: https://apify.com/harvestedge/discord-message-sentiment.md
- **Developed by:** [Harvest Edge](https://apify.com/harvestedge) (community)
- **Categories:** Lead generation, E-commerce, Social media
- **Features:** Full permissions
- **Stats:** 4 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 Sentiment

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

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

**Harvest Edge** makes business information available to everyone!

### 🌼 Overview

The **Discord Message Sentiment Scraper** collects message data — including text, embeds, attachments, reactions, and mentions — and performs **real-time sentiment analysis** using the **VADER Sentiment Analyzer**.

This tool is designed for developers, data scientists, and analysts who need structured conversational data for research, analytics, or community insights.\
It can scrape messages in either **"older"** or **"newer"** directions from a specific message ID, batching data safely to comply with Discord rate limits.

***

### 🌾 Features

- 🧠 **Sentiment analysis**
- 📦 **Structured output** with message metadata, attachments, embeds, and reactions
- ⏱ **Configurable batch delay** to prevent API throttling
- 🔁 **Directional scraping** (`newer` or `older`)
- 🚫 **Robust error handling** with descriptive logs
- ⚙️ **Optimized performance** (fetches up to 10,000 messages per run)
- 💬 Works with **Discord user tokens** for full message access

***

### 🔑 How to Get Your Discord Token

1. Open **Developer Tools** in your browser (`F12` key) and go to **discord.com/channels/@me**
2. Click the **Network** tab and filter for **Fetch/XHR**
3. Refresh the page if needed and look for a request named **@me**
4. Under **Request Headers**, locate the **Authorization** field
5. Copy the long token string — that’s your **Discord Token**

***

### ⚙️ Input Configuration

The Actor accepts the following input parameters via Apify:

| Key                   | Type    | Description                                                                                                                  | Default     | Required |
|-----------------------|---------|------------------------------------------------------------------------------------------------------------------------------|-------------|----------|
| `guild_id`            | String  | The ID of the Discord server (guild) containing the target channel.                                                          | -           | ✅ Yes    |
| `channel_id`          | String  | The ID of the channel from which to fetch messages.                                                                          | -           | ✅ Yes    |
| `token`               | String  | Your Discord user account token for authentication.                                                                          | -           | ✅ Yes    |
| `max_messages`        | Integer | Maximum number of messages to fetch (1–10,000).                                                                              | `1000`      | ❌ No     |
| `start_message_id`    | String  | Optional message ID to start scraping from.                                                                                  | `None`      | ❌ No     |
| `scrape_direction`    | String  | Direction of scrape: `"newer"` or `"older"`.                                                                                 | `newer`     | ❌ No     |
| `batch_delay_seconds` | String  | Delay between message batches (in seconds, to manage rate limits).                                                           | `1.0`       | ❌ No     |

***

### 🧾 Output Structure

Each message is output as a JSON object in your Apify dataset.

| Field                | Description |
|----------------------|-------------|
| `message_id`         | Unique message ID |
| `channel_id`         | Channel ID |
| `author`             | Object containing author details (`id`, `username`, `discriminator`, `avatar`, `public_flags`) |
| `content`            | Text content of the message |
| `timestamp`          | UTC timestamp of when the message was created |
| `edited_timestamp`   | Timestamp if the message was edited |
| `type`               | Discord message type (e.g., default, reply) |
| `attachments`        | List of attachments (ID, filename, URL, size, etc.) |
| `embeds`             | List of embeds (title, description, URL, thumbnail, etc.) |
| `pinned`             | Boolean — whether message is pinned |
| `mention_everyone`   | Boolean — whether the message mentions everyone |
| `tts`                | Boolean — whether the message was text-to-speech |
| `flags`              | Integer — Discord message flags |
| `components`         | Array of UI components (e.g., buttons) |
| `reactions`          | Array of reactions (emoji details, count, etc.) |
| `mentions`           | Array of mentioned users (ID, username, discriminator) |
| `message_reference`  | Object containing reply reference data |
| `sentiment`          | Object with sentiment scores (`pos`, `neu`, `neg`, `compound`, `label`) |

***

#### 🧠 Example Output

````json
{
  "message_id": "123456789012345678",
  "channel_id": "987654321098765432",
  "author": {
    "id": "111222333444555666",
    "username": "example_user",
    "discriminator": "1234",
    "avatar": "https://cdn.discordapp.com/avatars/...png",
    "public_flags": 0
  },
  "content": "This is awesome!",
  "timestamp": "2025-10-20 14:30:00",
  "edited_timestamp": null,
  "attachments": [],
  "embeds": [],
  "pinned": false,
  "mention_everyone": false,
  "tts": false,
  "flags": 0,
  "components": [],
  "reactions": [],
  "mentions": [],
  "message_reference": null,
  "sentiment": {
    "compound": 0.8316,
    "pos": 0.7,
    "neu": 0.3,
    "neg": 0.0,
    "label": "positive"
  }
}



# 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-sentiment").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-sentiment").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-sentiment --silent --output-dataset

```

## MCP server setup

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

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/b1xULBjTbC93lR6j2/builds/a1DQcDgYgNwbo6YFA/openapi.json
