Retrieve comprehensive forum data from Discord.js 14 thread start message
P粉337385922
P粉337385922 2024-03-29 16:54:08
0
1
305

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粉337385922
P粉337385922

reply all(1)
P粉794851975

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
    // ...
  }
});
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!