blob: 09e03d3f827015c90404de4fd431b9e116743856 [file] [log] [blame]
pineafan32767212022-03-14 21:27:39 +00001import log from '../utils/log.js'
2import readConfig from '../utils/readConfig.js'
3import convertCurlyBracketString from '../utils/convertCurlyBracketString.js'
4
5export async function callback(_, member) {
6 if (member.bot) return
7 let config = await readConfig(member.guild.id);
8 if (!config.welcome.enabled) return
9
10 if (!config.welcome.verificationRequired.role) {
11 if (config.welcome.welcomeRole) {
12 try {
13 await member.roles.add(config.welcome.welcomeRole)
14 } catch (err) {
15 console.error(err)
16 }
17 }
18 }
19
pineafan32767212022-03-14 21:27:39 +000020 if (!config.welcome.verificationRequired.message && config.welcome.channel) {
21 let string = config.welcome.message
22 if (string) {
23 string = await convertCurlyBracketString(string, member.id, member.displayName, member.guild.name, member.guild.members)
24
25 if (config.welcome.channel === 'dm') {
26 try {
27 await member.send(string)
28 } catch (err) {
29 console.error(err)
30 }
31 } else {
32 let channel = await member.client.channels.fetch(config.welcome.channel)
33 if (channel.guild.id !== member.guild.id) return
pineafan377794f2022-04-18 19:01:01 +010034 if (!channel) return
pineafan32767212022-03-14 21:27:39 +000035 try {
36 await channel.send(string)
37 } catch (err) {
38 console.error(err)
39 }
40 }
41 }
42 }
43}