blob: 5b80fbd944c6bc57b0e2e26832456d59691754b4 [file] [log] [blame]
pineafan813bdf42022-07-24 10:39:10 +01001import log from '../utils/log.js'
2import convertCurlyBracketString from '../utils/convertCurlyBracketString.js'
3import client from '../utils/client.js';
4
5export async function callback(_, member) {
6 if (member.bot) return
7 let config = await client.database.guilds.read(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
20 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
34 if (!channel) return
35 try {
36 await channel.send(string)
37 } catch (err) {
38 console.error(err)
39 }
40 }
41 }
42 }
43}