sending messages code problem

I wrote some codes that sends a image 'sendthis.jpg' to the chat if there's no messages for 45 minutes.

require('dotenv').config();
const { Client, Intents } = require('discord.js');
const fs = require('fs');

const client = new Client({ intents: [Intents.FLAG.GUILD, Intents.FLAGS.GUILD_MESSAGES] });

let lastMessageTimestamp = null;
const channelID = '1019570335818981427';
const imagePath = 'src/sendthis.jpg';
const timeLimit = 45 * 60 * 1000;

client.on('ready', () => {
    console.log(`Logged in as ${client.user.tag}!`);
    const channel = client.channels.cache.get(channelID);
    if (!channel) {
        console.error(`Channel with ID ${channelID} not found`);
        return;
    }
    channel.messages.fetch({ limit: 1 }).then(messages => {
        const lastMessage = messages.first();
        if (lastMessage) {
            lastMessageTimestamp = lastMessage.createdTimestamp;
        }
    });
});

client.on('messageCreate', message => {
    if (message.channel.id === channelID) {
        lastMessageTimestamp = message.createdTimestamp;
    }
});

setInterval(() => {
    if (lastMessageTimestamp && Date.now() - lastMessageTimestamp > timeLimit) {
        const channel = client.channels.cache.get(channelID);
        if (channel) {
            const file = new Discord.MessageAttachment(imagePath);
            channel.send({ files: [file] });
            lastMessageTimestamp = null;
        }
    }
}, 1000);

client.login(process.env.TOKEN);


And when I run this, terminal says 'TypeError: Cannot read properties of undefined (reading 'FLAG')
how can I fix it?
Was this page helpful?