🥅 fromUser not exist
This commit is contained in:
parent
b5b84b4862
commit
c0e6266910
4 changed files with 28 additions and 36 deletions
|
@ -8,13 +8,9 @@ module.exports = async (interaction) => {
|
||||||
try {
|
try {
|
||||||
const user = await interaction.options.getUser('user');
|
const user = await interaction.options.getUser('user');
|
||||||
|
|
||||||
console.log(interaction.member.guild.id);
|
|
||||||
|
|
||||||
await credits
|
await credits
|
||||||
.findOne({ userId: user ? user.id : interaction.user.id, guildId: interaction.member.guild.id })
|
.findOne({ userId: user ? user.id : interaction.user.id, guildId: interaction.member.guild.id })
|
||||||
.then(async (data) => {
|
.then(async (data) => {
|
||||||
console.log(data);
|
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Balance',
|
title: 'Balance',
|
||||||
|
|
|
@ -20,31 +20,21 @@ module.exports = async (interaction) => {
|
||||||
const from = await interaction.options.getUser('from');
|
const from = await interaction.options.getUser('from');
|
||||||
const to = await interaction.options.getUser('to');
|
const to = await interaction.options.getUser('to');
|
||||||
const amount = await interaction.options.getInteger('amount');
|
const amount = await interaction.options.getInteger('amount');
|
||||||
const data = await credits.findOne({ userId: from.id, guildId: interaction.member.guild.id });
|
// eslint-disable-next-line max-len
|
||||||
|
|
||||||
if (amount <= 0) {
|
|
||||||
const embed = {
|
|
||||||
title: 'Transfer failed',
|
|
||||||
description: "You can't transfer zero or below.",
|
|
||||||
color: 0xbb2124,
|
|
||||||
timestamp: new Date(),
|
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
|
||||||
};
|
|
||||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
|
||||||
}
|
|
||||||
if (data.balance < amount) {
|
|
||||||
const embed = {
|
|
||||||
title: 'Transfer',
|
|
||||||
description: `${from.username} has insufficient credits. ${from.username} balance is ${data.balance}`,
|
|
||||||
color: 0xbb2124,
|
|
||||||
timestamp: new Date(),
|
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
|
||||||
};
|
|
||||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
|
||||||
}
|
|
||||||
const fromUser = await credits.findOne({ userId: from.id, guildId: interaction.member.guild.id });
|
const fromUser = await credits.findOne({ userId: from.id, guildId: interaction.member.guild.id });
|
||||||
const toUser = await credits.findOne({ userId: to.id, guildId: interaction.member.guild.id });
|
const toUser = await credits.findOne({ userId: to.id, guildId: interaction.member.guild.id });
|
||||||
|
|
||||||
|
if (!fromUser) {
|
||||||
|
const embed = {
|
||||||
|
title: 'Transfer',
|
||||||
|
description: 'That user has no credits, I can not transfer credits from the user',
|
||||||
|
color: config.colors.error,
|
||||||
|
timestamp: new Date(),
|
||||||
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
|
};
|
||||||
|
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
|
}
|
||||||
|
|
||||||
if (!toUser) {
|
if (!toUser) {
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Transfer',
|
title: 'Transfer',
|
||||||
|
@ -56,15 +46,25 @@ module.exports = async (interaction) => {
|
||||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fromUser) {
|
if (amount <= 0) {
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Transfer',
|
title: 'Transfer failed',
|
||||||
description: 'That user has no credits, I can not transfer credits from the user',
|
description: "You can't transfer zero or below.",
|
||||||
color: config.colors.error,
|
color: 0xbb2124,
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
|
}
|
||||||
|
if (fromUser.balance < amount) {
|
||||||
|
const embed = {
|
||||||
|
title: 'Transfer',
|
||||||
|
description: `${from.username} has insufficient credits. ${from.username} balance is ${fromUser.balance}`,
|
||||||
|
color: 0xbb2124,
|
||||||
|
timestamp: new Date(),
|
||||||
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
|
};
|
||||||
|
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
fromUser.balance -= amount;
|
fromUser.balance -= amount;
|
||||||
|
@ -87,7 +87,7 @@ module.exports = async (interaction) => {
|
||||||
await logger.debug(`Gift sent from: ${interaction.user.username} to: ${to.username}`);
|
await logger.debug(`Gift sent from: ${interaction.user.username} to: ${to.username}`);
|
||||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
} catch {
|
} catch {
|
||||||
await logger.error();
|
logger.error();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,7 +9,5 @@ module.exports = {
|
||||||
const guildExist = await guilds.findOne({ guildId: guild.id });
|
const guildExist = await guilds.findOne({ guildId: guild.id });
|
||||||
|
|
||||||
if (!guildExist) { await guilds.create({ guildId: guild.id }); }
|
if (!guildExist) { await guilds.create({ guildId: guild.id }); }
|
||||||
|
|
||||||
console.log(guildExist);
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,8 +16,6 @@ module.exports = {
|
||||||
|
|
||||||
if (!guildExist) { await guilds.create({ guildId: interaction.member.guild.id }); }
|
if (!guildExist) { await guilds.create({ guildId: interaction.member.guild.id }); }
|
||||||
|
|
||||||
console.log(guildExist);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await interaction.deferReply({
|
await interaction.deferReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
|
|
Loading…
Add table
Reference in a new issue