aboutsummaryrefslogtreecommitdiff
path: root/src/context-menu-commands/user/userInfo.ts
blob: 283e4a06419fe215bff33369057632b7ad6766fb (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
31
32
33
34
35
36
37
38
import { UserInfoCommand } from '#commands';
import { emojis } from '#lib';
import { ContextMenuCommand } from '@notenoughupdates/discord-akairo';
import assert from 'assert';
import { ApplicationCommandType, GuildMember, UserContextMenuCommandInteraction } from 'discord.js';

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

	public override async exec(interaction: UserContextMenuCommandInteraction) {
		if (!interaction.inCachedGuild())
			return interaction.reply({
				content: `${emojis.error} You can't use this command outside of a server.`,
				ephemeral: true
			});

		await interaction.deferReply({ ephemeral: true });

		const user = interaction.targetUser;

		const guild = interaction.guild ?? undefined;

		const member = interaction.targetMember ?? undefined;

		assert(member instanceof GuildMember || member === undefined);

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

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