# Create Discord Feed

## User Intent

"How do I sync Discord server messages? Show me Discord feed configuration."

## Operation

**SDK Method**: `createFeed()` with FeedTypes.Discord\
**Auth**: Bot token required

***

## Code Example (TypeScript)

```typescript
import { Graphlit } from 'graphlit-client';
import {
  FeedTypes,
  FeedListingTypes,
  DiscordChannelsInput,
  DiscordGuildsInput,
} from 'graphlit-client/dist/generated/graphql-types';

const graphlit = new Graphlit();

const discordAuth: DiscordGuildsInput = {
  token: process.env.DISCORD_BOT_TOKEN!,
};

// Enumerate guilds (servers) the bot can access
const guildsResponse = await graphlit.queryDiscordGuilds(discordAuth);
const guilds = guildsResponse.discordGuilds?.results ?? [];

if (guilds.length === 0) {
  throw new Error('No Discord guilds available for the provided bot token');
}

const guild = guilds[0]!;
console.log(`Using Discord guild: ${guild.guildName} (${guild.guildId})`);

// Enumerate channels inside the selected guild
const channelsResponse = await graphlit.queryDiscordChannels({
  guildId: guild.guildId!,
  token: discordAuth.token,
});

const channels = channelsResponse.discordChannels?.results ?? [];

if (channels.length === 0) {
  throw new Error('No Discord channels available in the selected guild');
}

const channel = channels[0]!;
console.log(`Using Discord channel: ${channel.channelName}`);

const feed = await graphlit.createFeed({
  name: 'Discord Server',
  type: FeedTypes.Discord,
  discord: {
    type: FeedListingTypes.Past,
    token: discordAuth.token,
    channel: channel.channelName!,
    readLimit: 500,
    includeAttachments: true,
  },
  // Optional: assign workflow for custom processing
  // workflow: { id: workflow.createWorkflow.id }
});

console.log(`Created Discord feed: ${feed.createFeed.id}`);
```

***

## Configuration

**token**: Discord bot token (from Developer Portal)\
**channel**: Discord channel name (enumerate via `queryDiscordChannels`)\
**type**: `FeedListingTypes.Past` or `FeedListingTypes.New`\
**readLimit**: Messages per sync window\
**includeAttachments**: Enable to capture file uploads

***

## Discord Bot Setup

1. Discord Developer Portal → Create Application
2. Bot → Add Bot
3. Copy bot token
4. Invite bot to server with Read Messages, Read Message History, and Attach Files permissions
5. Use helper queries to discover guild and channel names

***

## What Gets Synced

* Text messages
* Mentions
* Embeds
* Attachments
* Message reactions (metadata)

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.graphlit.dev/api-guides/use-cases/feeds/messaging/feed-create-discord.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
