skopa/commands/currency/inventory.js

25 lines
907 B
JavaScript
Raw Normal View History

//Boring init stuff
const { SlashCommandBuilder } = require('discord.js');
const helpers = require('../../helpers.js');
const { Users } = require('../../dbObjects.js');
module.exports = {
//Creates the slash command
data: new SlashCommandBuilder()
.setName('inventory')
.setDescription('Shows your (or a specified user\'s) inventory.')
.addUserOption(option =>
option
.setName('user')
.setDescription('User\'s inventory to display')),
//Executes said slash command
async execute(interaction) {
const target = interaction.options.getUser('user') ?? interaction.user;
const user = await Users.findOne({ where: { user_id: target.id } });
const items = await user.getItems();
if (!items.length) return interaction.reply(`${target.tag} has no items ;v;`);
return interaction.reply(`${target.tag} currently has ${items.map(i => `${i.amount} ${i.item.name}`).join(', ')}`);
},
};