1
votes

I am trying to build a Discord Economy Bot and I am trying to dynamically give a user-specified amount of money to all members who have the mentioned role. When I run my code, no errors show. However, money isn't added to each member.

Example command: e!maasyatir @role xmoney

const Discord = require('discord.js');
const db = require('quick.db');

exports.run = async (bot, message, args, member) => {
 if (!args[0]) return message.reply('Bir Sayı Girmen Gerek.');

 if (!message.member.permissions.has('ADMINISTRATOR')) {
  return message.reply('Bunu Yapmaya Yetkin Yok.');
 }

 let user = message.mentions.roles.first();
 if (isNaN(args[1])) return;
 db.add(`money_${message.guild.id}_${user}`, args[1]);

 let moneyEmbed = new Discord.MessageEmbed()
  .setColor('RANDOM')
  .setDescription(
   `✅ | ${user} Rolüne Sahip Kişilere ${args[1]} Değerinde Para Eklendi.`
  );
 message.channel.send(moneyEmbed);
};

module.exports.help = {
 name: 'maasyatir',
 aliases: ['maas'],
};
1

1 Answers

1
votes

You'll probably want to go through all users with the role and then add the money to each user.

if (isNaN(args[1])) return;
    
let role = message.mentions.roles.first();
    
role.members.map(user => {  
 db.add(`money_${message.guild.id}_${user.id}`, args[1])
});