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)
|
typeof autoArchiveMinutesRaw === "number" && Number.isFinite(autoArchiveMinutesRaw)
|
||||||
? autoArchiveMinutesRaw
|
? autoArchiveMinutesRaw
|
||||||
: undefined;
|
: 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
|
const thread = accountId
|
||||||
? await createThreadDiscord(
|
? await createThreadDiscord(channelId, payload, { accountId })
|
||||||
channelId,
|
: await createThreadDiscord(channelId, payload);
|
||||||
{ name, messageId, autoArchiveMinutes },
|
|
||||||
{ accountId },
|
|
||||||
)
|
|
||||||
: await createThreadDiscord(channelId, { name, messageId, autoArchiveMinutes });
|
|
||||||
return jsonResult({ ok: true, thread });
|
return jsonResult({ ok: true, thread });
|
||||||
}
|
}
|
||||||
case "threadList": {
|
case "threadList": {
|
||||||
|
|||||||
@ -183,6 +183,10 @@ export async function handleDiscordMessageAction(
|
|||||||
const autoArchiveMinutes = readNumberParam(params, "autoArchiveMin", {
|
const autoArchiveMinutes = readNumberParam(params, "autoArchiveMin", {
|
||||||
integer: true,
|
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(
|
return await handleDiscordAction(
|
||||||
{
|
{
|
||||||
action: "threadCreate",
|
action: "threadCreate",
|
||||||
@ -191,6 +195,9 @@ export async function handleDiscordMessageAction(
|
|||||||
name,
|
name,
|
||||||
messageId,
|
messageId,
|
||||||
autoArchiveMinutes,
|
autoArchiveMinutes,
|
||||||
|
content,
|
||||||
|
appliedTags,
|
||||||
|
embeds,
|
||||||
},
|
},
|
||||||
cfg,
|
cfg,
|
||||||
);
|
);
|
||||||
|
|||||||
@ -97,6 +97,22 @@ export async function createThreadDiscord(
|
|||||||
if (payload.autoArchiveMinutes) {
|
if (payload.autoArchiveMinutes) {
|
||||||
body.auto_archive_duration = 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);
|
const route = Routes.threads(channelId, payload.messageId);
|
||||||
return await rest.post(route, { body });
|
return await rest.post(route, { body });
|
||||||
}
|
}
|
||||||
|
|||||||
@ -66,10 +66,19 @@ export type DiscordMessageEdit = {
|
|||||||
content?: string;
|
content?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type DiscordForumMessage = {
|
||||||
|
content: string;
|
||||||
|
embeds?: unknown[];
|
||||||
|
};
|
||||||
|
|
||||||
export type DiscordThreadCreate = {
|
export type DiscordThreadCreate = {
|
||||||
messageId?: string;
|
messageId?: string;
|
||||||
name: string;
|
name: string;
|
||||||
autoArchiveMinutes?: number;
|
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 = {
|
export type DiscordThreadList = {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user