T
T
theinlao2020-09-14 17:51:07
Node.js
theinlao, 2020-09-14 17:51:07

How to make a random issue of currency?

How to make it so that not 200 coins are given, but from 100 to 500 for example

const Discord = require("discord.js");
const db = require("quick.db");
const ms = require("parse-ms");

module.exports.run = async (bot, message, args) => {
  if(!message.content.startsWith('!'))return;  

  let user = message.author;

  let timeout = 86400000;
  let amount = 200;

  let daily = await db.fetch(`daily_${message.guild.id}_${user.id}`);

  if (daily !== null && timeout - (Date.now() - daily) > 0) {
    let time = ms(timeout - (Date.now() - daily));
  
    let timeEmbed = new Discord.MessageEmbed()
    .setAuthor(`Daily`, message.author.displayAvatarURL)
    .setColor("GREEN")
    .setDescription(`Вы уже забрали свою ежедневную награду, забери награду снова через ${time.hours}ч ${time.minutes}м ${time.seconds}с `);
    message.channel.send(timeEmbed)
  } else {
    let moneyEmbed = new Discord.MessageEmbed()
  .setColor("GREEN")
  .setDescription(`Вы получили ежедневную награду в размере ${amount} коинов`);
  message.channel.send(moneyEmbed)
  db.add(`money_${message.guild.id}_${user.id}`, amount)
  db.set(`daily_${message.guild.id}_${user.id}`, Date.now())


  }
};

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-09-14
@Alexandre888

function random(min, max) {
  let rand = min - 0.5 + Math.random() * (max - min + 1);
  return Math.round(rand);
}

usage:
random(min, max);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question