/inventory
This commit is contained in:
parent
2a2cdb8dff
commit
4351e6dfad
|
@ -0,0 +1,27 @@
|
|||
import { GuildMember, Interaction, SlashCommandBuilder } from 'discord.js';
|
||||
import { ItemInventory, db } from '../lib/db';
|
||||
import { formatItems, getItem } from '../lib/items';
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('inventory')
|
||||
.setDescription('Check your inventory')
|
||||
.setDMPermission(false),
|
||||
|
||||
execute: async (interaction: Interaction, member: GuildMember) => {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
|
||||
await interaction.deferReply({ephemeral: true});
|
||||
|
||||
const itemsList = await db<ItemInventory>('itemInventories')
|
||||
.select('item', 'quantity')
|
||||
.where('user', member.user.id);
|
||||
|
||||
// kind of stupid kind of awful
|
||||
const items = (await Promise.all(itemsList.map(async i => ({item: await getItem(i.item), quantity: i.quantity})))).filter(i => i.item);
|
||||
|
||||
await interaction.followUp(
|
||||
`Your inventory:\n${items.length === 0 ? '_Your inventory is empty!_' : items.map(i => `- ${formatItems(i.item!, i.quantity)}`).join('\n')}`
|
||||
);
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue