Advertisement

TrimwebsolutionsTrimwebsolutions

Problem and Solutions

Send a message every 5 seconds with Client.on('ready', () => { }); on Node.js

By M.K. Verma Β· 2 May 2022

Send a message every 5 seconds with Client.on('ready', () => { }); on Node.js
const Discord = require("discord.js");
const Client = new Discord.Client;
const fs = require('fs')
const userCoin = JSON.parse(fs.readFileSync('Storage/userCoin.json', 'utf-8'));

function doSomething() {
    const guild = Client.guilds.cache.get('925830522138148976');
    const channel2up22 = guild.channels.cache.get('966206342740181012');

    let Embed = new Discord.MessageEmbed()
        .setTitle("Wild Gift 🎁 ! | GuinGame - v2.0 🎰")
        .setColor('#caabd0')
        .setDescription("Be the **first** to react ``'πŸš€'`` to this message to win **10 πŸͺ™!**")
        .setThumbnail("https://media.giphy.com/media/Jv1Xu8EBCOynpoGBwd/giphy.gif")
        .setFooter(text="πŸ€– GuinbearBot  |  🌐 Guinbeargang.io")
        .setTimestamp()
    channel2up22.send(Embed).then(message => {
        message.react('πŸš€');
    }).catch(console.error);
}

Client.on('messageReactionAdd', (reaction, user) => {
    const guild = Client.guilds.cache.get('925830522138148976');
    const channel2up22 = guild.channels.cache.get('966206342740181012');
    if (reaction.message.channel.id == channel2up22) {
    if (reaction.emoji.name == 'πŸš€' && user.id !== "936254253285146635") {
        reaction.message.delete();
        var Magic09 = 1;
        while (Magic09 <= 10) {
            userCoin[user.id].CoinsAmount;
            Magic09++;
        }
        fs.writeFile('Storage/userCoin.json', JSON.stringify(userCoin), (err) => {
            if (err) console.error(err);
        })
        let Embed = new Discord.MessageEmbed()
            .setTitle("Wild Gift 🎁 ! | GuinGame - v2.0 🎰")
            .setColor('#caabd0')
            .setDescription(`${user} has won the **Wild Gift 🎁 !**`)
            .setThumbnail("https://media.giphy.com/media/Jv1Xu8EBCOynpoGBwd/giphy.gif")
            .setFooter(text="πŸ€– GuinbearBot  |  🌐 Guinbeargang.io")
            .setTimestamp()
        channel2up22.send(Embed)
        
    }
}
});

Client.on('ready', () => {
    setInterval(doSomething, 5000)
});