-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
invite.ts
72 lines (67 loc) · 2.04 KB
/
invite.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
import { URL } from "url"
import * as app from "#app"
export default new app.Command({
name: "invite",
description: "Generate an invitation link",
aliases: ["invitation", "bot", "cobaye"],
channelType: "all",
positional: [
app.positional({
name: "bot",
type: "user",
validate: (user) => user.bot,
description: "Bot to invite",
validationErrorMessage: "User must be a bot.",
}),
],
flags: [
{
name: "here",
flag: "H",
description: "Generate link for the current guild",
},
],
async run(message) {
const here: boolean = message.args.here
const bot: app.User = message.args.bot
const url = new URL("/oauth2/authorize", "https://discord.com/")
url.searchParams.append("scope", "bot applications.commands")
url.searchParams.append("client_id", bot.id)
if (here && app.isGuildMessage(message)) {
url.searchParams.append("permissions", "0")
url.searchParams.append("guild_id", message.guild.id)
} else {
url.searchParams.append("permissions", "2146958847")
}
await message.channel.send({
embeds: [
new app.EmbedBuilder()
.setAuthor({
name: `Invitez ${bot.username} ${here ? "ici" : ""}`,
iconURL: message.guild?.iconURL() ?? undefined,
url: url.toString(),
})
.setDescription(
await app.code.stringify({
content: JSON.stringify(
Object.fromEntries(url.searchParams.entries()),
(key, val) => {
if (
/^\d+$/.test(val) &&
val.length < 12 &&
!val.startsWith("0")
)
return Number(val)
return val
},
2,
),
lang: "json",
}),
)
.setThumbnail(bot.displayAvatarURL())
.setURL(url.toString()),
],
})
},
})