#Check timestamp of a message

11 messages · Page 1 of 1 (latest)

hidden nimbus
#

Hey i have try to get the timestamp of the l’a test message but she said « message.createdTimestamp() » isn’t a function🤔

Can anybody help me ? thx

guild.channels.cache
        .filter((channel) => channel.name.includes("ticket"))
        .forEach((channel) => {
          console.log(channel.name);
          channel.messages.fetch({ limit: 1 }).then(message => {
            let lastMessage = message.createdTimestamp();
            console.log(lastMessage);
          })
        });
lyric ravenBOT
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

hidden nimbus
#

i m on lastest DJS and node V16

blissful monolith
#

<Message>.createdTimestamp is a property

hidden nimbus
blissful monolith
#

just change .createdTimestamp() to .createdTimestamp

hidden nimbus
# blissful monolith just change `.createdTimestamp()` to `.createdTimestamp`

Oh thx but now i have this error x)

TypeError: Cannot read properties of undefined (reading 'fetch')

module.exports = {
  name: "ready",
  once: true,
  async execute(client) {
    const guild = client.guilds.cache.get("942024668859220069");

    setInterval(() => {
      guild.channels.cache
        .filter((channel) => channel.name.includes("aide"))
        .forEach((channel) => {
          console.log(channel.name);
          channel.messages.fetch({ limit: 1 }).then((messages) => {
            let lastMessage = messages.first();
            let time = lastMessage.createdTimestamp;
            console.log(time)
          });
        });
    }, 60 * 60 * 1000);
  },
};
blissful monolith
#

not all channels have messages

#

filter them using <Channel>#isTextBased()

hidden nimbus
#

thx ^^

hidden nimbus
# blissful monolith filter them using `<Channel>#isTextBased()`

If i wanna check the message has sent 1 hour ago how i can do this ? x)

const d = new Date( time ); // Time of the message was sent
date = d.getHours() + ":" + d.getMinutes();

const dActual = new Date( Date.now() );
dateActual = dActual.getHours() + ":" + dActual.getMinutes();