如何在 discord.js 中记录频道中的每条消息?不和谐 v11

时间:2021-02-03 21:39:27

标签: javascript discord discord.js

我正在尝试获取特定频道中的每条消息并将其记录到控制台,我已经尝试破解此问题已有一段时间了,但我永远无法获取超过 100 条消息,我不知道如何循环 fetchMessages 所以我可以得到 100 多个,这是我的代码:

const Discord = require('discord.js'); //dependency
const client = new Discord.Client();



client.on('ready', () => { //when the bot turns on, it says its on in console
  console.log(`Logged in as ${client.user.tag}!`);
  client.channels.get('790493949474635797').fetchMessages({limit:100}).then(messages=>{
    messages
    .forEach(message =>console.log(`"${message.author.tag}", ${
      (() => {
        const unixTimestamp = message.createdTimestamp
        const dateObject = new Date(unixTimestamp)
        var d = new Date(unixTimestamp);
        var utc = d.getTime(unixTimestamp);
        var nd = new Date(utc + (3600000*0))
        return nd.toLocaleString()
      })()}:\n${message.content}`))
  })
});

任何帮助将不胜感激!

0 个答案:

没有答案