aboutsummaryrefslogtreecommitdiff
path: root/src/context-menu-commands/user/userInfo.ts
blob: 0d19cce4a42489ba557bb5e501f35c3636581b0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { format } from '#lib';
import { ContextMenuCommand } from 'discord-akairo';
import { ApplicationCommandType, type ContextMenuCommandInteraction, type Guild } from 'discord.js';
import UserInfoCommand from '../../commands/info/userInfo.js';

export default class UserInfoContextMenuCommand extends ContextMenuCommand {
	public constructor() {
		super('userInfo', {
			name: 'User Info',
			type: ApplicationCommandType.User,
			category: 'user'
		});
	}

	public override async exec(interaction: ContextMenuCommandInteraction) {
		await interaction.deferReply({ ephemeral: true });

		const user = await this.client.users.fetch(interaction.targetId).catch(() => null);
		if (!user) return interaction.reply(`⁉ I couldn't find that user`);

		const guild = interaction.guild as Guild;

		const member = await guild.members.fetch(interaction.targetId).catch(() => null);
		if (!member) return interaction.reply(`${format.input(user.tag)} doesn't appear to be a member of this server anymore.`);

		const userEmbed = await UserInfoCommand.makeUserInfoEmbed(user, member, guild);

		return await interaction.editReply({ embeds: [userEmbed] });
	}
}