Skip to content

Commit 9927d79

Browse files
committed
(fix): fix bug on transfer command
1 parent a198c82 commit 9927d79

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

commands/social/transfer.js

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,41 @@ module.exports = {
1313
run: (client, message, [ friend='', amount='' ]) => profile.findById(message.author.id, async (err, doc) => {
1414

1515
const fr = friend;
16-
friend = await message.guild.members.fetch(friend.match(/\d{17,19}/)||[][0]||' ')
16+
friend = await message.guild.members.fetch(friend.match(/\d{17,19}/)?.[0]||' ')
1717
.catch(()=>{});
1818

19-
amount = Math.round(amount.split(',').join(''));
19+
amount = Math.round(amount.split(',').join('')) || 'Nothing';
2020

2121
if (err){
22-
return message.channel.send(`\`❌ [DATABASE_ERR]:\` The database responded with error: ${err.name}`);
22+
return message.channel.send(`\`❌ [DATABASE_ERR]:\` The database responded with error: \`${err.name}\``);
2323
} else if (!doc || doc.data.economy.wallet === null){
24-
return message.channel.send(`\\❌ **${message.member.displayName}**, You don't have a **wallet** yet!\nTo create one, type \`${client.prefix}register\`.`);
24+
return message.channel.send(`\\❌ **${message.author.tag}**, You don't have a **wallet** yet!\nTo create one, type \`${client.prefix}register\`.`);
2525
} else if (doc.data.economy.bank === null){
26-
return message.channel.send(`\\❌ **${message.member.displayName}**, You don't have a **bank** yet!\nTo create one, type \`${client.prefix}bank\`.`);
26+
return message.channel.send(`\\❌ **${message.author.tag}**, You don't have a **bank** yet!\nTo create one, type \`${client.prefix}bank\`.`);
27+
} else if (!fr){
28+
return message.channel.send(`\\❌ **${message.author.tag}**, please specify the user you want to give credits to!`);
2729
} else if (!friend){
28-
return message.channel.send(`\\❌ **${message.member.displayName}**, I couldn't find ${fr} in this server!`);
29-
} else if (!amount){
30-
return message.channel.send(`\\❌ **${message.member.displayName}**, **${amount}** is not a valid amount!`);
30+
return message.channel.send(`\\❌ **${message.author.tag}**, I couldn't find \`${fr}\` in this server!`);
31+
} else if (!amount || amount === 'Nothing'){
32+
return message.channel.send(`\\❌ **${message.author.tag}**, **${amount}** is not a valid amount!`);
3133
} else if (amount < 100 || amount > 20000){
32-
return message.channel.send(`\\❌ **${message.member.displayName}**, only valid amount to transfer is between **100** and **20,000**!`);
34+
return message.channel.send(`\\❌ **${message.author.tag}**, only valid amount to transfer is between **100** and **20,000**!`);
3335
} else if (Math.ceil(amount * 1.1) > doc.data.economy.bank){
34-
return message.channel.send(`\\❌ **${message.member.displayName}**, Insuffecient credits! You only have **${text.commatize(doc.data.economy.bank)}** in your bank! (10% fee applies)`);
36+
return message.channel.send(`\\❌ **${message.author.tag}**, Insuffecient credits! You only have **${text.commatize(doc.data.economy.bank)}** in your bank! (10% fee applies)`);
3537
};
3638

37-
const friendName = friend.displayName;
38-
friend = await profile.findById(friend.id).catch(()=>{});
39+
const friendName = friend.user.tag;
40+
friend = await profile.findById(friend.id).catch(err => err);
3941

40-
if (!(friend instanceof profile)){
41-
return message.channel.send(`\`❌ [DATABASE_ERR]:\` The database responded with error: ${err.name}`);
42-
};
43-
44-
if (!friend || friend.economy.data.bank === null){
45-
return message.channel.send(`\\❌ **${message.member.displayName}**, **${friend.displayName}** doesn't have a bank yet! He is not yet eligible to receive credits!`);
42+
if (!friend || friend.data.economy.bank === null){
43+
return message.channel.send(`\\❌ **${message.author.tag}**, **${friendName}** doesn't have a bank yet! He is not yet eligible to receive credits!`);
4644
};
4745

4846
doc.data.economy.bank = doc.data.economy.bank - Math.floor(amount * 1.1);
4947
friend.data.economy.bank = friend.data.economy.bank + amount;
5048

5149
return Promise.all([ doc.save(), friend.save() ])
52-
.then(()=> message.channel.send(`\\✔️ **${message.member.displayName}**, successfully transferred **${amount}**`))
53-
.catch(()=> message.channel.send(`❌ [DATABASE_ERR]:\` The database responded with error: ${err.name}`));
50+
.then(()=> message.channel.send(`\\✔️ **${message.author.tag}**, successfully transferred **${amount}** to **${friendName}**`))
51+
.catch(err => message.channel.send(`\`❌ [DATABASE_ERR]:\` The database responded with error: \`${err.name}\``));
5452
})
5553
};

0 commit comments

Comments
 (0)