Let's say I wanted my bot to greet me at my birthday and have my bot greet me in a direct message every single year. How can we achieve it ?
Code :
const { Client, MessageEmbed, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const d = new Date();
const minutes = d.getMinutes();
client.once('ready', () => {
console.log('beep boop thirdy is online');
}
)
client.on('messageCreate', message => {
if(message.content === '!dm')
client.users.fetch('471298666586570762', false).then((user) => {
user.send("test")
});
})
client.login('token');
This can be achieved by an answer in this post, You can use a similar method but you will need to account for a possible leap year every 4 years
You also need to update the datestr1 each year after a check and save it in a database
const datestr1 = "7/13/2015"
const datestr2 = "7/13/2016"
const date1 = new Date(datestr1);
const date2 = new Date(datestr2);
const diffTime = Math.abs(date2 - date1);
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
const currdateyear = parseInt(datestr2.substring(datestr2.length - 4))
if (currdateyear % 4 === 0) {
if (diffDays === 366) console.log("happy bday")
} else if (diffDays === 365) console.log("happy bday")