fix(discord): support forum channel thread-create (#10062)

* fix(discord): support forum channel thread-create

* fix: harden discord forum thread-create (#10062) (thanks @jarvis89757)

---------

Co-authored-by: Shakker <shakkerdroid@gmail.com>
This commit is contained in:
jarvis89757
2026-02-08 16:51:10 +11:00
committed by GitHub
parent bc475f0172
commit 9949f82590
10 changed files with 136 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
import type { APIMessage } from "discord-api-types/v10";
import { Routes } from "discord-api-types/v10";
import type { APIChannel, APIMessage } from "discord-api-types/v10";
import { ChannelType, Routes } from "discord-api-types/v10";
import type {
DiscordMessageEdit,
DiscordMessageQuery,
@@ -105,7 +105,26 @@ export async function createThreadDiscord(
if (payload.autoArchiveMinutes) {
body.auto_archive_duration = payload.autoArchiveMinutes;
}
const route = Routes.threads(channelId, payload.messageId);
let channelType: ChannelType | undefined;
if (!payload.messageId) {
// Only detect channel kind for route-less thread creation.
// If this lookup fails, keep prior behavior and let Discord validate.
try {
const channel = (await rest.get(Routes.channel(channelId))) as APIChannel | null | undefined;
channelType = channel?.type;
} catch {
channelType = undefined;
}
}
const isForumLike =
channelType === ChannelType.GuildForum || channelType === ChannelType.GuildMedia;
if (isForumLike) {
const starterContent = payload.content?.trim() ? payload.content : payload.name;
body.message = { content: starterContent };
}
const route = payload.messageId
? Routes.threads(channelId, payload.messageId)
: Routes.threads(channelId);
return await rest.post(route, { body });
}