mardi 22 mars 2022

How can I send a random message everyday from an array at a specific hour on discord.js?

I'm trying to make a bot that will send a random message from an array using cron.

Here is my code:

const cron = require('cron');

module.exports = {
    name: 'pesanrandom',
    description: "random message every day",
    execute(message, args, cmd, client, Discord){
      let scheduledMessage = new cron.CronJob('00 54 16 * * *', () => {
        //
        var listPesan = [
          'Met siang guys, dah pada mam siang blum?',
          'Siapa yang tadi pagi mimpiin cowo atau cewe kpopnya',
          'Siang-siang enaknya...',
          'Dor kaget ga',
          'Laper dah',
        ];

        var pesanRandom = listPesan[Math.floor(Math.random() * listPesan.length)];

        const pesanEmbed = new Discord.MessageEmbed()
              .setColor('#50C878')
              .setTitle('vermillion#3039')
              .setDescription(pesanRandom)
              .setFooter('© Vermillion')

        client.channels.cache.get('927589065925214239').send(pesanEmbed);
        //
      });

      scheduledMessage.start()
    }
}

I already try the code and it works but it can only randomize the message one time. How to make it randomize the message everytime the message is sent?




Aucun commentaire:

Enregistrer un commentaire