feat(discord): add forum channel thread (post) support
Adds support for creating threads in Discord forum channels via the
message tool's thread-create action.
Forum channels require an initial message object when creating a post,
unlike regular text channel threads. This change:
- Adds 'message' parameter for forum post content (required for forums)
- Adds 'appliedTags' parameter for forum tag IDs
- Updates DiscordThreadCreate type with new optional fields
- Updates createThreadDiscord to include message/tags in API payload
- Updates action handlers to pass through new parameters
Usage:
message action=thread-create channelId=<forum-id> \
threadName='Post Title' \
message='Initial post content' \
appliedTags='["tag-id-1", "tag-id-2"]'
Fixes: Discord forum thread creation was not possible via message tool
This commit is contained in:
parent
1cca0e5072
commit
b2daa8bb51
@ -284,13 +284,33 @@ export async function handleDiscordMessagingAction(
|
||||
typeof autoArchiveMinutesRaw === "number" && Number.isFinite(autoArchiveMinutesRaw)
|
||||
? autoArchiveMinutesRaw
|
||||
: undefined;
|
||||
|
||||
// Forum channel support: initial message content
|
||||
const messageContent = readStringParam(params, "content");
|
||||
const appliedTags = readStringArrayParam(params, "appliedTags");
|
||||
const embeds =
|
||||
Array.isArray(params.embeds) && params.embeds.length > 0 ? params.embeds : undefined;
|
||||
|
||||
const payload: Parameters<typeof createThreadDiscord>[1] = {
|
||||
name,
|
||||
messageId,
|
||||
autoArchiveMinutes,
|
||||
};
|
||||
|
||||
// Add forum-specific fields if content is provided
|
||||
if (messageContent) {
|
||||
payload.message = {
|
||||
content: messageContent,
|
||||
embeds,
|
||||
};
|
||||
}
|
||||
if (appliedTags?.length) {
|
||||
payload.appliedTags = appliedTags;
|
||||
}
|
||||
|
||||
const thread = accountId
|
||||
? await createThreadDiscord(
|
||||
channelId,
|
||||
{ name, messageId, autoArchiveMinutes },
|
||||
{ accountId },
|
||||
)
|
||||
: await createThreadDiscord(channelId, { name, messageId, autoArchiveMinutes });
|
||||
? await createThreadDiscord(channelId, payload, { accountId })
|
||||
: await createThreadDiscord(channelId, payload);
|
||||
return jsonResult({ ok: true, thread });
|
||||
}
|
||||
case "threadList": {
|
||||
|
||||
@ -183,6 +183,10 @@ export async function handleDiscordMessageAction(
|
||||
const autoArchiveMinutes = readNumberParam(params, "autoArchiveMin", {
|
||||
integer: true,
|
||||
});
|
||||
// Forum channel support
|
||||
const content = readStringParam(params, "message");
|
||||
const appliedTags = readStringArrayParam(params, "appliedTags");
|
||||
const embeds = Array.isArray(params.embeds) ? params.embeds : undefined;
|
||||
return await handleDiscordAction(
|
||||
{
|
||||
action: "threadCreate",
|
||||
@ -191,6 +195,9 @@ export async function handleDiscordMessageAction(
|
||||
name,
|
||||
messageId,
|
||||
autoArchiveMinutes,
|
||||
content,
|
||||
appliedTags,
|
||||
embeds,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
|
||||
@ -97,6 +97,22 @@ export async function createThreadDiscord(
|
||||
if (payload.autoArchiveMinutes) {
|
||||
body.auto_archive_duration = payload.autoArchiveMinutes;
|
||||
}
|
||||
|
||||
// Forum channels require a message object for the initial post
|
||||
if (payload.message) {
|
||||
body.message = {
|
||||
content: payload.message.content,
|
||||
...(payload.message.embeds?.length ? { embeds: payload.message.embeds } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
// Forum tags
|
||||
if (payload.appliedTags?.length) {
|
||||
body.applied_tags = payload.appliedTags;
|
||||
}
|
||||
|
||||
// For forum channels without messageId, use the channel threads endpoint
|
||||
// For regular channels with messageId, use the message-based thread endpoint
|
||||
const route = Routes.threads(channelId, payload.messageId);
|
||||
return await rest.post(route, { body });
|
||||
}
|
||||
|
||||
@ -66,10 +66,19 @@ export type DiscordMessageEdit = {
|
||||
content?: string;
|
||||
};
|
||||
|
||||
export type DiscordForumMessage = {
|
||||
content: string;
|
||||
embeds?: unknown[];
|
||||
};
|
||||
|
||||
export type DiscordThreadCreate = {
|
||||
messageId?: string;
|
||||
name: string;
|
||||
autoArchiveMinutes?: number;
|
||||
/** Initial message content for forum posts (required for forum channels) */
|
||||
message?: DiscordForumMessage;
|
||||
/** Tag IDs to apply to forum posts */
|
||||
appliedTags?: string[];
|
||||
};
|
||||
|
||||
export type DiscordThreadList = {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user