Files
discord-rpg-concept/src/commands/inventory/inventory.ts

45 lines
1.6 KiB
TypeScript

import { createCommand } from "@/lib/utils";
import { SlashCommandBuilder, EmbedBuilder } from "discord.js";
import { inventoryService } from "@/modules/inventory/inventory.service";
import { userService } from "@/modules/user/user.service";
export const inventory = createCommand({
data: new SlashCommandBuilder()
.setName("inventory")
.setDescription("View your or another user's inventory")
.addUserOption(option =>
option.setName("user")
.setDescription("User to view")
.setRequired(false)
),
execute: async (interaction) => {
await interaction.deferReply();
const targetUser = interaction.options.getUser("user") || interaction.user;
const user = await userService.getOrCreateUser(targetUser.id, targetUser.username);
const items = await inventoryService.getInventory(user.id);
if (!items || items.length === 0) {
const embed = new EmbedBuilder()
.setTitle(`${user.username}'s Inventory`)
.setDescription("Inventory is empty.")
.setColor("Blue");
await interaction.editReply({ embeds: [embed] });
return;
}
const description = items.map(entry => {
return `**${entry.item.name}** x${entry.quantity}`;
}).join("\n");
const embed = new EmbedBuilder()
.setTitle(`${user.username}'s Inventory`)
.setDescription(description)
.setColor("Blue")
.setTimestamp();
await interaction.editReply({ embeds: [embed] });
}
});