1 |
import { formatDistanceToNowStrict } from "date-fns"; |
2 |
import { Message, Interaction, CacheType, CommandInteraction, Guild, GuildPreview } from "discord.js"; |
3 |
import Client from "../../client/Client"; |
4 |
import MessageEmbed from "../../client/MessageEmbed"; |
5 |
import CommandOptions from "../../types/CommandOptions"; |
6 |
import InteractionOptions from "../../types/InteractionOptions"; |
7 |
import { emoji } from "../../utils/Emoji"; |
8 |
import BaseCommand from "../../utils/structures/BaseCommand"; |
9 |
|
10 |
export default class GuildLookupCommand extends BaseCommand { |
11 |
constructor() { |
12 |
super("guildlookup", "information", ["glookup", "guild"]); |
13 |
} |
14 |
|
15 |
async run(client: Client, message: CommandInteraction<CacheType> | Message<boolean>, options: CommandOptions | InteractionOptions): Promise<void> { |
16 |
if (!options.isInteraction && options.args[0] === undefined) { |
17 |
await message.reply(`${emoji('error')} You must provide the guild/server ID to lookup.`); |
18 |
return; |
19 |
} |
20 |
|
21 |
const inputID = options.isInteraction ? options.options.getString("guild_id")! : options.args[0]; |
22 |
let guild: GuildPreview | undefined; |
23 |
|
24 |
try { |
25 |
guild = await client.fetchGuildPreview(inputID); |
26 |
|
27 |
if (!guild) { |
28 |
guild = undefined; |
29 |
} |
30 |
} |
31 |
catch (e) { |
32 |
console.log(e); |
33 |
} |
34 |
|
35 |
if (!guild) { |
36 |
await message.reply(`${emoji('error')} No guild/server was found with that ID or the guild isn't a public server.`); |
37 |
return; |
38 |
} |
39 |
|
40 |
await message.reply({ |
41 |
embeds: [ |
42 |
new MessageEmbed({ |
43 |
author: { |
44 |
name: guild.name, |
45 |
iconURL: guild.iconURL() ?? undefined |
46 |
}, |
47 |
description: guild.description ?? '*No description available*', |
48 |
fields: [ |
49 |
{ |
50 |
name: "Approximate Member Count", |
51 |
value: guild.approximateMemberCount + '', |
52 |
inline: true |
53 |
}, |
54 |
{ |
55 |
name: "Approximate Presence Count", |
56 |
value: guild.approximatePresenceCount + '', |
57 |
inline: true |
58 |
}, |
59 |
{ |
60 |
name: "Created", |
61 |
value: `${guild.createdAt.toLocaleString()} (${formatDistanceToNowStrict(guild.createdAt, { addSuffix: true })})`, |
62 |
}, |
63 |
], |
64 |
thumbnail: guild.splashURL() ? { |
65 |
url: guild.splashURL()! |
66 |
} : undefined, |
67 |
footer: { |
68 |
text: `${guild.id}` |
69 |
} |
70 |
}) |
71 |
.setTimestamp() |
72 |
] |
73 |
}); |
74 |
} |
75 |
} |