Create Discord Feed
User Intent
Operation
Code Example (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
Discord Bot Setup
What Gets Synced
Last updated