userinfo.ts

1import {
2	ChatInputCommandInteraction,
3	EmbedBuilder,
4	SlashCommandBuilder,
5} from 'discord.js'
6import { Command } from '@/types/bot'
7
8export default {
9	data: new SlashCommandBuilder()
10		.setName('userinfo')
11		.setDescription('Get information about a user')
12		.addUserOption((option) =>
13			option
14				.setName('target')
15				.setDescription('The user to get info about')
16				.setRequired(false),
17		),
18
19	async execute(interaction: ChatInputCommandInteraction) {
20		const target = interaction.options.getUser('target') ?? interaction.user
21		const member = interaction.guild?.members.cache.get(target.id)
22
23		const embed = new EmbedBuilder()
24			.setColor('#0099ff')
25			.setTitle('User Information')
26			.setThumbnail(target.displayAvatarURL())
27			.addFields(
28				{ name: 'Username', value: target.username, inline: true },
29				{ name: 'ID', value: target.id, inline: true },
30				{
31					name: 'Account Created',
32					value: `<t:${Math.floor(target.createdTimestamp / 1000)}:R>`,
33					inline: true,
34				},
35				{
36					name: 'Joined Server',
37					value:
38						member ?
39							`<t:${Math.floor(member.joinedTimestamp! / 1000)}:R>`
40						:	'N/A',
41					inline: true,
42				},
43				{
44					name: 'Roles',
45					value:
46						member ?
47							member.roles.cache.map((role) => role.toString()).join(', ')
48						:	'N/A',
49				},
50			)
51			.setTimestamp()
52
53		await interaction.reply({ embeds: [embed] })
54	},
55} as Command
56