-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
traffic.guildMemberAdd.ts
85 lines (70 loc) · 2.35 KB
/
traffic.guildMemberAdd.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
import * as app from "#app"
import { filename } from "dirname-filename-esm"
const __filename = filename(import.meta)
export default new app.Listener({
event: "guildMemberAdd",
description: "Prepares to welcome a new member",
async run(member) {
if (!app.cache.ensure<boolean>("turn", true)) return
if (await app.isIgnored(member.guild.id)) return
const config = await app.getGuild(member.guild, { forceExists: true })
await app.applyAutoRoles(member)
if (member.user.bot) {
if (config.bot_role_id)
await member.roles
.add(config.bot_role_id)
.catch((error) => app.error(error, __filename))
if (config.general_channel_id && config.bot_welcome_message) {
const general = member.client.channels.cache.get(
config.general_channel_id,
)
if (general && general.isSendable())
await app.sendTemplatedEmbed(
general,
config.bot_welcome_message,
app.embedReplacers(member),
)
}
} else {
if (config.member_role_id)
await member.roles
.add(config.member_role_id)
.catch((error) => app.error(error, __filename, true))
if (config.member_welcome_direct_message) {
try {
const dm = await member.createDM(true)
await app.sendTemplatedEmbed(
dm,
config.member_welcome_direct_message,
app.embedReplacers(member),
)
} catch {}
}
if (config.general_channel_id && config.member_welcome_message) {
const general = member.client.channels.cache.get(
config.general_channel_id,
)
if (general && general.isSendable())
await app.sendTemplatedEmbed(
general,
config.member_welcome_message,
app.embedReplacers(member),
)
}
if (!(await app.getUser(member))) {
try {
const message = await member.send(
"Welcome to the **Les Laboratoires** network.\nOne of these servers may be of interest to you!",
)
if (message.channel.isSendable())
await app.sendLabList(message.channel, 10)
} catch {}
}
}
return app.sendLog(
member.guild,
`${member.user} is a new **${member.user.bot ? "bot" : "member"}**.`,
config,
)
},
})