♻️ credits balance

This commit is contained in:
Axel Olausson Holtenäs 2022-04-13 21:11:04 +02:00
parent 512ef3d3c0
commit d458f0e18f
No known key found for this signature in database
GPG key ID: 9347A5E873995701

View file

@ -16,36 +16,46 @@ import fetchUser from "@helpers/fetchUser";
export default { export default {
data: (command: SlashCommandSubcommandBuilder) => { data: (command: SlashCommandSubcommandBuilder) => {
return command return (
.setName("balance") command
.setDescription("Check a user's balance.") .setName("balance")
.addUserOption((option) => .setDescription("Check a user's balance.")
option
.setName("user") // User
.setDescription("The user whose balance you want to check.") .addUserOption((option) =>
.setRequired(false) option
); .setName("user")
.setDescription("The user whose balance you want to check.")
)
);
}, },
execute: async (interaction: CommandInteraction) => { execute: async (interaction: CommandInteraction) => {
// Destructure
const { options, user, guild } = interaction; const { options, user, guild } = interaction;
// User option const discordUser = options?.getUser("user");
const optionUser = options?.getUser("user");
if (guild === null) return; if (guild === null) {
return interaction?.editReply({
embeds: [
new MessageEmbed()
.setTitle("[:dollar:] Credits (Balance)")
.setDescription(`We can not find your guild!`)
.setTimestamp(new Date())
.setColor(errorColor)
.setFooter({ text: footerText, iconURL: footerIcon }),
],
});
}
// Get credit object const userObj = await fetchUser(discordUser || user, guild);
const userObj = await fetchUser(optionUser || user, guild);
// If userObj does not exist
if (userObj === null) { if (userObj === null) {
return interaction?.editReply({ return interaction?.editReply({
embeds: [ embeds: [
new MessageEmbed() new MessageEmbed()
.setTitle("[:dollar:] Credits (Balance)") .setTitle("[:dollar:] Credits (Balance)")
.setDescription( .setDescription(
`We can not find ${optionUser || "you"} in our database!` `We can not find ${discordUser || "you"} in our database!`
) )
.setTimestamp(new Date()) .setTimestamp(new Date())
.setColor(errorColor) .setColor(errorColor)
@ -54,7 +64,6 @@ export default {
}); });
} }
// If userObj.credits does not exist
if (userObj.credits === null) { if (userObj.credits === null) {
return interaction?.editReply({ return interaction?.editReply({
embeds: [ embeds: [
@ -62,7 +71,7 @@ export default {
.setTitle("[:dollar:] Credits (Balance)") .setTitle("[:dollar:] Credits (Balance)")
.setDescription( .setDescription(
`We can not find credits for ${ `We can not find credits for ${
optionUser || "you" discordUser || "you"
} in our database!` } in our database!`
) )
.setTimestamp(new Date()) .setTimestamp(new Date())
@ -77,7 +86,7 @@ export default {
new MessageEmbed() new MessageEmbed()
.setTitle("[:dollar:] Credits (Balance)") .setTitle("[:dollar:] Credits (Balance)")
.setDescription( .setDescription(
`${optionUser || "You"} have ${pluralize( `${discordUser || "You"} have ${pluralize(
userObj.credits, userObj.credits,
"credit" "credit"
)}.` )}.`