search

Home  >  Q&A  >  body text

Retrieve comprehensive forum data from Discord.js 14 thread start message

I am relatively new to discord.js and node. I'm trying to read the first message from a thread, I don't know, as an array and save it later. Because I want to pass the data via API later.

I'm breaking my crown here.

I've tried:

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
    }
})

But I can't find a way to get wohl thread data. Maybe someone can help me solve this problem?

P粉337385922P粉337385922238 days ago325

reply all(1)I'll reply

  • P粉794851975

    P粉7948519752024-03-30 10:48:33

    const { ChannelType } = require('discord.js');
    
    client.on('threadCreate', async (thread) => {
      if (thread.type === ChannelType.GuildPublicThread) {
        const messages = await thread.messages.fetch();
        const firstMessage = messages.first();
    
        // Access the data of the first message
        console.log(firstMessage.content); // Example: Log the content of the first message
    
        // You can save the necessary data from the first message for later use in your API
        const messageData = {
          content: firstMessage.content,
          author: firstMessage.author.tag,
          // Add more properties as needed
        };
    
        // Pass the messageData to your API or perform further operations
        // ...
      }
    });

    reply
    0
  • Cancelreply