node.jsdiscorddiscord.js

How to get the name of forum post : discord.js


With my Discord servers now having access to Forum Channels, I want to extend my word checker bot to also check forum post names.

How would I get the forum post name/object?

Also, is there a way to do some sort of: client.on("newPost", ...)?


Solution

  • I had the same question but I found the answer by searching on the Discord API page. The new Post event is a threadCreate event!

    Also, the name of the thread is the name of the forum post. I didn't found yet how to get all images, emojis and the description but I think it will soon be added in Discord.JS!

    Try this:

    const { ChannelType } = require('discord.js');
    
    client.on('threadCreate', async (thread) => {
        if (thread.type == ChannelType.GuildPublicThread) {
            // When a new forum post is created
            console.log(thread.parentId) // The forum channel ID
            console.log(thread.id) // The forum post ID
            console.log(thread.name) // The name of the forum post
        }
    })
    

    Hope this helps!