closeForumTopic
Returns: TrueOfficial docs ↗
Use this method to close an open topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.
Parameters
chat_idIntegerStringRequiredUnique identifier for the target chat or username of the target supergroup (in the format
@supergroupusername)message_thread_idIntegerRequiredUnique identifier for the target message thread of the forum topic
Returns
On success, True is returned.
GramIO Usage
ts
// Close a forum topic by chat ID and thread ID
await bot.api.closeForumTopic({
chat_id: "@mysupergroup",
message_thread_id: 123,
});ts
// Close the topic that triggered the current message
bot.on("message", async (ctx) => {
if (ctx.threadId && ctx.chat?.type === "supergroup") {
await bot.api.closeForumTopic({
chat_id: ctx.chatId,
message_thread_id: ctx.threadId,
});
await ctx.send("This topic has been closed.");
}
});ts
// Admin command to close a topic using a numeric ID from user input
bot.command("closetopic", async (ctx) => {
const threadId = Number(ctx.args);
if (!threadId) {
return ctx.reply("Usage: /closetopic <thread_id>");
}
await bot.api.closeForumTopic({
chat_id: ctx.chatId,
message_thread_id: threadId,
});
await ctx.reply(`Topic ${threadId} has been closed.`);
});Errors
| Code | Error | Cause |
|---|---|---|
| 400 | Bad Request: chat not found | chat_id is invalid or the bot has no access to the chat |
| 400 | Bad Request: TOPIC_NOT_MODIFIED | The topic is already closed — no action taken |
| 400 | Bad Request: message thread not found | message_thread_id does not exist in this chat |
| 403 | Forbidden: not enough rights | Bot is not an admin or lacks can_manage_topics right, and is not the topic creator |
| 400 | Bad Request: supergroup required | Forum topics only exist in supergroups with forum mode enabled |
Tips & Gotchas
- Forum mode must be enabled. The chat must be a supergroup with forum mode active. Calling this on a regular group or channel returns an error.
- Topic creator exemption. The bot can close a topic it created without
can_manage_topicsadmin rights. For topics created by others, the bot needs the right explicitly. - General topic uses a different method. The 'General' topic cannot be closed with
closeForumTopic— usecloseGeneralForumTopicinstead. message_thread_idis the topic ID. In GramIO contexts, access it viactx.threadId. Messages sent to a topic carry this ID.- Closing doesn't delete the topic. Users can still read the conversation; new messages simply cannot be posted. Use
deleteForumTopicto remove the topic entirely.
See Also
reopenForumTopic— reopen a previously closed topiceditForumTopic— change the topic name or icondeleteForumTopic— permanently delete a forum topiccreateForumTopic— create a new forum topiccloseGeneralForumTopic— close the General topic specificallyunpinAllForumTopicMessages— clear pinned messages from a topicForumTopic— the ForumTopic type