From 6f4ff1df0622aaa8e3429b31b0d2647ab2dd95ba Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Thu, 4 Jul 2024 18:56:05 +0100 Subject: [PATCH] Add user option --- src/commands/304276391837302787/moons.ts | 6 +++++- src/commands/304276391837302787/moons/list.ts | 8 +++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/commands/304276391837302787/moons.ts b/src/commands/304276391837302787/moons.ts index 1556d97..5c8fc85 100644 --- a/src/commands/304276391837302787/moons.ts +++ b/src/commands/304276391837302787/moons.ts @@ -12,7 +12,11 @@ export default class Moons extends Command { .addSubcommand(subcommand => subcommand .setName('list') - .setDescription('List moons you have obtained')); + .setDescription('List moons you have obtained') + .addUserOption(option => + option + .setName("user") + .setDescription("The user to view (Defaults to yourself)"))); } public override async execute(interaction: CommandInteraction) { diff --git a/src/commands/304276391837302787/moons/list.ts b/src/commands/304276391837302787/moons/list.ts index d862d5c..b359f2f 100644 --- a/src/commands/304276391837302787/moons/list.ts +++ b/src/commands/304276391837302787/moons/list.ts @@ -3,17 +3,19 @@ import Moon from "../../../database/entities/Moon"; import EmbedColours from "../../../constants/EmbedColours"; export default async function ListMoons(interaction: CommandInteraction) { - const moons = await Moon.FetchMoonsByUserId(interaction.user.id); + const user = interaction.options.get("user")?.user ?? interaction.user; + + const moons = await Moon.FetchMoonsByUserId(user.id); if (!moons || moons.length == 0) { - await interaction.reply("You do not have any moons."); + await interaction.reply(`${user.username} does not have any moons.`); return; } const description = moons.flatMap(x => `${x.MoonNumber}. ${x.Description.slice(0, 15)}`); const embed = new EmbedBuilder() - .setTitle(`${interaction.user.username}'s Moons`) + .setTitle(`${user.username}'s Moons`) .setColor(EmbedColours.Ok) .setDescription(description.join("\n")) .setFooter({ text: `${moons.length} moons` });