added balance
This commit is contained in:
@@ -1,13 +1,29 @@
|
|||||||
import { createCommand } from "@lib/utils";
|
import { createCommand } from "@lib/utils";
|
||||||
import { getUserBalance } from "@/modules/economy/economy.service";
|
import { getUserBalance } from "@/modules/economy/economy.service";
|
||||||
import { SlashCommandBuilder, EmbedBuilder } from "discord.js";
|
import { createUser, getUserById } from "@/modules/users/users.service";
|
||||||
|
import { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits } from "discord.js";
|
||||||
|
|
||||||
export const balance = createCommand({
|
export const balance = createCommand({
|
||||||
data: new SlashCommandBuilder().setName("balance").setDescription("Check your balance"),
|
data: new SlashCommandBuilder()
|
||||||
execute: async (interaction) => {
|
.setName("balance")
|
||||||
const balance = await getUserBalance(interaction.user.id) || 0;
|
.setDescription("Check your balance")
|
||||||
const embed = new EmbedBuilder().setDescription(`Your balance is ${balance}`);
|
|
||||||
|
|
||||||
|
, execute: async (interaction) => {
|
||||||
|
const user = interaction.user;
|
||||||
|
// Ensure user exists in DB
|
||||||
|
let dbUser = await getUserById(user.id);
|
||||||
|
if (!dbUser) {
|
||||||
|
await createUser(user.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const balance = await getUserBalance(user.id);
|
||||||
|
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setTitle(`${user.username}'s Balance`)
|
||||||
|
.setDescription(`💰 **${balance} coins**`)
|
||||||
|
.setColor("Green");
|
||||||
|
|
||||||
await interaction.reply({ embeds: [embed] });
|
await interaction.reply({ embeds: [embed] });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Reference in New Issue
Block a user