forked from notunderctrl/discordjs-v14-series
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
167fb4a
commit 579341d
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const { Client, Interaction, ApplicationCommandOptionType } = require('discord.js'); | ||
const User = require('../../models/User'); | ||
|
||
module.exports = { | ||
/** | ||
* | ||
* @param {Client} client | ||
* @param {Interaction} interaction | ||
*/ | ||
callback: async (client, interaction) => { | ||
if (!interaction.inGuild()) { | ||
interaction.reply({ | ||
content: 'You can only run this command inside a server.', | ||
ephemeral: true, | ||
}); | ||
return; | ||
} | ||
|
||
const targetUserId = interaction.options.get('user')?.value || interaction.member.id; | ||
|
||
await interaction.deferReply(); | ||
|
||
const user = await User.findOne({ userId: targetUserId, guildId: interaction.guild.id }); | ||
|
||
if (!user) { | ||
interaction.editReply(`<@${targetUserId}> doesn't have a profile yet.`); | ||
return; | ||
} | ||
|
||
interaction.editReply( | ||
targetUserId === interaction.member.id | ||
? `Your balance is **${user.balance}**` | ||
: `<@${targetUserId}>'s balance is **${user.balance}**` | ||
); | ||
}, | ||
|
||
name: 'balance', | ||
description: "See yours/someone else's balance", | ||
options: [ | ||
{ | ||
name: 'user', | ||
description: 'The user whose balance you want to get.', | ||
type: ApplicationCommandOptionType.User, | ||
}, | ||
], | ||
}; |