Skip to main content
Glama

discord_create_forum_post

Generate and publish a new post in a Discord forum channel, including a title, content, and optional tags, using the MCP-Discord server for streamlined communication.

Instructions

Creates a new post in a Discord forum channel with optional tags

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYes
forumChannelIdYes
tagsNo
titleYes

Implementation Reference

  • The main handler function that executes the Discord forum post creation using discord.js, including validation, tag resolution, and error handling.
    export const createForumPostHandler: ToolHandler = async (args, { client }) => {
      const { forumChannelId, title, content, tags } = CreateForumPostSchema.parse(args);
      
      try {
        if (!client.isReady()) {
          return {
            content: [{ type: "text", text: "Discord client not logged in." }],
            isError: true
          };
        }
    
        const channel = await client.channels.fetch(forumChannelId);
        if (!channel || channel.type !== ChannelType.GuildForum) {
          return {
            content: [{ type: "text", text: `Channel ID ${forumChannelId} is not a forum channel.` }],
            isError: true
          };
        }
    
        const forumChannel = channel as ForumChannel;
        
        // Get available tags in the forum
        const availableTags = forumChannel.availableTags;
        let selectedTagIds: string[] = [];
        
        // If tags are provided, find their IDs
        if (tags && tags.length > 0) {
          selectedTagIds = availableTags
            .filter(tag => tags.includes(tag.name))
            .map(tag => tag.id);
        }
    
        // Create the forum post
        const thread = await forumChannel.threads.create({
          name: title,
          message: {
            content: content
          },
          appliedTags: selectedTagIds.length > 0 ? selectedTagIds : undefined
        });
    
        return {
          content: [{ 
            type: "text", 
            text: `Successfully created forum post "${title}" with ID: ${thread.id}` 
          }]
        };
      } catch (error) {
        return handleDiscordError(error);
      }
    };
  • Zod runtime validation schema for the tool's input parameters.
    export const CreateForumPostSchema = z.object({
        forumChannelId: z.string(),
        title: z.string(),
        content: z.string(),
        tags: z.array(z.string()).optional()
    });
  • JSON Schema definition for the tool, used by MCP for tool discovery and client-side validation.
    {
      name: "discord_create_forum_post",
      description: "Creates a new post in a Discord forum channel with optional tags",
      inputSchema: {
        type: "object",
        properties: {
          forumChannelId: { type: "string" },
          title: { type: "string" },
          content: { type: "string" },
          tags: {
            type: "array",
            items: { type: "string" }
          }
        },
        required: ["forumChannelId", "title", "content"]
      }
    },
  • src/server.ts:103-106 (registration)
    Tool handler registration and dispatch in the MCP server's tool execution switch statement.
    case "discord_create_forum_post":
      this.logClientState("before discord_create_forum_post handler");
      toolResponse = await createForumPostHandler(args, this.toolContext);
      return toolResponse;

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/barryyip0625/mcp-discord'

If you have feedback or need assistance with the MCP directory API, please join our Discord server