Rumah  >  Soal Jawab  >  teks badan

Dapatkan semula data forum komprehensif daripada mesej mula benang Discord.js 14

Saya agak baru dengan discord.js dan node. Saya cuba membaca mesej pertama daripada benang, saya tidak tahu, sebagai tatasusunan dan simpan kemudian. Sebab saya nak pass data melalui API nanti.

Saya memecahkan mahkota saya di sini.

Saya dah cuba:

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

Tetapi saya tidak dapat mencari cara untuk mendapatkan data benang wohl. Mungkin seseorang boleh membantu saya menyelesaikan masalah ini?

P粉337385922P粉337385922203 hari yang lalu281

membalas semua(1)saya akan balas

  • 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
        // ...
      }
    });

    balas
    0
  • Batalbalas