Heim  >  Fragen und Antworten  >  Hauptteil

Rufen Sie umfassende Forendaten aus der 14-Thread-Startnachricht von Discord.j ab

Ich bin relativ neu bei discord.js und node. Ich versuche, die erste Nachricht aus einem Thread, den ich nicht kenne, als Array zu lesen und später zu speichern. Weil ich die Daten später per API übergeben möchte.

Ich zerbreche hier meine Krone.

Ich habe es versucht:

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

Aber ich finde keine Möglichkeit, die Wohl-Thread-Daten abzurufen. Vielleicht kann mir jemand bei der Lösung dieses Problems helfen?

P粉337385922P粉337385922204 Tage vor282

Antworte allen(1)Ich werde antworten

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

    Antwort
    0
  • StornierenAntwort