从 Discord.js 14 线程启动消息中检索综合论坛数据
P粉337385922
P粉337385922 2024-03-29 16:54:08
[JavaScript讨论组]

我对discord.js 与node 相对较新。我正在尝试从线程中读取第一条消息,我不知道,作为数组并稍后保存。因为我想稍后通过 API 传递数据。

我在这里打破了我的王冠。

我已经尝试过:

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

但我找不到获取 wohl 线程数据的方法。也许有人可以帮我解决这个问题?

P粉337385922
P粉337385922

全部回复(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
    // ...
  }
});
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号