Skip to content
Snippets Groups Projects
Commit 22530c16 authored by Reviath's avatar Reviath
Browse files

Update commands/send.js

parent 75bcb921
No related branches found
No related tags found
No related merge requests found
const Discord = require('discord.js');
const db = require('quick.db');
exports.run = async(client, message, args) => {
exports.run = async(client, message, args, connection) => {
let sender = message.author.id;
let target = message.guild.member(message.mentions.users.first() || message.guild.members.cache.get(args[0]));
let amount = parseInt(args[1]);
if(!target) return message.channel.send('Who do you want to send?')
if (target.user.id == sender) return message.channel.send(`You can't send money to yourself`)
let bal = await db.get(`Balance_${message.author.id}`);
const cash = await new Promise((resolve, reject) => {
connection.query(`SELECT cash FROM cashes WHERE guildid ='${message.guild.id}' AND userid ='${message.author.id}'`, function (err, result) {
if (err)
reject(err);
resolve(result);
});
});
var bal = "";
if(cash.length < 1) {
bal = 0;
}
else {
bal = cash[0].cash
}
if (amount > bal || amount <= 0 || !bal) return message.channel.send(`Your balance is under the value you entered.`);
else{
await db.subtract(`Balance_${sender}`, amount);
await db.add(`Balance_${target.user.id}`, amount);
let sql = `UPDATE cashes SET cash ='${bal - amount}' WHERE guildid ='${message.guild.id}' AND userid ='${message.author.id}'`
connection.query(sql, function (err, result) {
if (err) throw err;
});
let sql2 = `UPDATE cashes SET cash ='${bal + amount}' WHERE guildid ='${message.guild.id}' AND userid ='${target.id}'`
connection.query(sql2, function (err, result) {
if (err) throw err;
});
message.channel.send(`Sent ${amount}$ to <@${target.user.id}>`)
}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment