-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
131 lines (105 loc) · 4.45 KB
/
main.js
File metadata and controls
131 lines (105 loc) · 4.45 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const discord = require('discord.js')
const client = new discord.Client({
intents: [
discord.GatewayIntentBits.GuildMessages,
discord.GatewayIntentBits.GuildMembers,
discord.GatewayIntentBits.GuildMessageReactions,
discord.GatewayIntentBits.Guilds,
discord.GatewayIntentBits.GuildPresences,
]
})
function embedcreator(path) {
let config = require('./config')
const { EmbedBuilder } = require('discord.js');
// get the config path
const args = path.split('.')
// get the config
let conf = config
// get item from config
args.forEach(argument => {
conf = conf[argument]
});
// create a new EmbedBuilder
const embed = new EmbedBuilder()
.setColor(conf.color || config.bot.color)
.setTitle(conf.title)
.setDescription(conf.description)
// check if the author iconURL and Footer iconURL is a url
if (conf.author?.iconURL && !conf.author.iconURL.startsWith('http')) conf.author.iconURL = null
if (conf.footer?.iconURL && !conf.footer.iconURL.startsWith('http')) conf.footer.iconURL = null
// set the author and footer
if (conf.footer?.text) embed.setFooter(conf.footer)
if (conf.author?.name) embed.setAuthor(conf.author)
// set the image, banner, timestamp and url
if (conf.image) embed.setThumbnail(conf.image)
if (conf.banner) embed.setImage(conf.banner)
if (conf.timestamp) embed.setTimestamp()
if (conf.url) embed.setURL(conf.url)
// add fields
if (conf.fields) conf.fields.forEach(filed => {
embed.addFields(filed)
});
// return the embed
return embed
}
const config = require('./config.js')
client.on('ready', () => {
console.log('Logged in as ' + client.user.tag + '!')
if (!config.bot.activitys) return
if (!config.bot.intervall) return
if (!config.bot.enabled) return
setInterval(() => {
let i = 0
const activity = config.bot.activitys[i]
client.user.setStatus(activity.status)
client.user.setActivity({ name: activity.name, type: activity.type })
i++
}, config.bot.intervall)
})
client.on('guildMemberAdd', async (member) => {
const channel = member.guild.channels.cache.get(config.messages.welcome.channel)
if (!channel) return
const embed = embedcreator('messages.welcome')
.setDescription(config.messages.welcome.description
.replace('{userping}', member.toString())
.replace('{username}', member.user.username)
.replace('{displayname}', member.displayName)
.replace('{ammountmember}', member.guild.memberCount)
)
if (config.messages.welcome.dm) try { member.send({ embeds: [embed] }) } catch (error) {}
channel.send({ embeds: [embed] })
config.messages.welcome.roles.forEach(role => {
const dcrole = member.guild.roles.cache.get(role)
if (!dcrole) return
member.roles.add(dcrole)
})
})
client.on('guildMemberRemove', async (member) => {
const channel = member.guild.channels.cache.get(config.messages.goodbye.channel)
if (!channel) return
const embed = embedcreator('messages.goodbye')
.setDescription(config.messages.goodbye.description
.replace('{userping}', member.toString())
.replace('{username}', member.user.username)
.replace('{displayname}', member.displayName)
.replace('{ammountmember}', member.guild.memberCount)
)
channel.send({ embeds: [embed] })
})
client.on('guildMemberUpdate', async (oldmember, newmember) => {
if (newmember.premiumSinceTimestamp === null) return
if (oldmember.premiumSinceTimestamp === newmember.premiumSinceTimestamp) return
const channel = newmember.guild.channels.cache.get(config.messages.boost.channel)
if (!channel) return
const embed = embedcreator('messages.boost')
.setDescription(config.messages.boost.description
.replace('{userping}', newmember.toString())
.replace('{username}', newmember.user.username)
.replace('{displayname}', newmember.displayName)
.replace('{ammountboosts}', newmember.guild.premiumSubscriptionCount)
)
if (config.messages.boost.dm) try { newmember.send({ embeds: [embed] }) } catch (error) {}
const msg = await channel.send({ embeds: [embed] })
if (config.messages.boost.reaction.enabled) msg.react(config.messages.boost.reaction.emoji)
})
client.login(config.bot.token)