-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinfo.ts
155 lines (141 loc) · 4.21 KB
/
info.ts
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import {
EmbedBuilder,
SlashCommandBuilder,
SlashCommandSubcommandBuilder,
} from 'discord.js';
import { COLORS, command, formatDate, reply } from 'utils';
import { CommandContext } from 'types';
const server = new SlashCommandSubcommandBuilder()
.setName('server')
.setDescription('Get some info about this server.');
const bot = new SlashCommandSubcommandBuilder()
.setName('bot')
.setDescription('Get some info about this bot.');
const user = new SlashCommandSubcommandBuilder()
.setName('user')
.setDescription('Get some info about a user.')
.addUserOption((option) =>
option
.setName('user')
.setDescription('The user to get info about.')
.setRequired(true)
);
const meta = new SlashCommandBuilder()
.setName('info')
.setDescription('Get some info about various things.')
.addSubcommand(server)
.addSubcommand(bot)
.addSubcommand(user);
export default command({
meta,
exec: async ({ interaction, ...ctx }) => {
await interaction.deferReply({ ephemeral: true });
switch (interaction.options.getSubcommand()) {
case 'server':
return await getServerInfo({ interaction, ...ctx });
case 'bot':
return await getBotInfo({ interaction, ...ctx });
case 'user':
return await getUserInfo({ interaction, ...ctx });
}
},
});
const getServerInfo = async ({ interaction }: CommandContext) => {
const owner = await interaction.guild?.fetchOwner();
const channels = await interaction.guild?.channels.fetch();
const embed = new EmbedBuilder()
.setTitle('Server Info')
.setDescription(`Info about ***${interaction.guild?.name}***`)
.setColor(COLORS.embed)
.setThumbnail(interaction.guild?.iconURL() ?? null)
.setFields([
{
name: 'Guild ID',
value: interaction.guildId ?? 'Unknown',
inline: false,
},
{
name: 'Owner',
value: owner?.user.username ?? 'Unknown',
inline: true,
},
{
name: 'Created',
value: interaction.guild
? formatDate(interaction.guild?.createdAt)
: 'Unknown',
inline: true,
},
{
name: 'Members',
value: interaction.guild?.memberCount?.toString() ?? 'Unknown',
inline: true,
},
{
name: 'Channels',
value: channels?.size?.toString() ?? 'Unknown',
inline: true,
},
{
name: 'Roles',
value: interaction.guild?.roles.cache.size?.toString() ?? 'Unknown',
inline: true,
},
]);
await reply(interaction, { embeds: [embed] });
};
const getBotInfo = async ({ interaction }: CommandContext) => {
const embed = new EmbedBuilder()
.setTitle('Bot Info')
.setDescription(`Info about ***${interaction.client.user?.username}***`)
.setColor(COLORS.embed)
.setThumbnail(interaction.client.user?.avatarURL() ?? null)
.setFields([
{
name: 'Bot ID',
value: interaction.client.user?.id ?? 'Unknown',
inline: false,
},
{
name: 'Created',
value: formatDate(interaction.client.user?.createdAt) ?? 'Unknown',
inline: true,
},
{
name: 'Guilds',
value: interaction.client.guilds.cache.size?.toString() ?? 'Unknown',
inline: true,
},
]);
await reply(interaction, { embeds: [embed] });
};
const getUserInfo = async ({ interaction }: CommandContext) => {
const user = interaction.options.getUser('user', true);
const member = await interaction.guild?.members.fetch(user.id);
if (!member) reply.error(interaction, { content: 'User not found' });
const embed = new EmbedBuilder()
.setTitle('User Info')
.setDescription(`Info about ***${user.username}***`)
.setColor(COLORS.embed)
.setThumbnail(user.avatarURL() ?? '')
.setFields([
{
name: 'User ID',
value: user.id ?? 'Unknown',
inline: false,
},
{
name: 'Created',
value: formatDate(user.createdAt) ?? 'Unknown',
inline: true,
},
{
name: 'Joined',
value: member && member.joinedAt
? formatDate(member.joinedAt)
: 'Unknown',
inline: true,
},
]);
await reply(interaction, { embeds: [embed] });
};