-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.js
335 lines (325 loc) · 11.8 KB
/
index.js
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
/*
Advanced Boost Announce System in Discord.js V14
Hope you Enjoy, Made with 🤍 by CalledMasih
Github: https://github.com/calledmasih | Don't forget to star the repositories.
Website: https://calledmasih.ir/
Copyright Masih 2024 All Right Reserved!
*/
require("./errorHandlers");
const {
Client,
GatewayIntentBits,
EmbedBuilder,
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
} = require("discord.js");
const chalk = require("chalk");
const config = require("./config.json");
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildPresences,
],
}); // Required intents, Don't remove any of them
client.on("guildMemberUpdate", async (oldMember, newMember) => {
// All Definitions
const boostAnnounceLogChannel = client.channels.cache.get(
config.boostLogsChannelId
);
const boostAnnounceChannel = client.channels.cache.get(
config.boostAnnounceChannelId
);
const format = {
0: "No Level",
1: "Level 1",
2: "Level 2",
3: "Level 3",
};
const boostLevel = format[newMember.guild.premiumTier];
const totalBoosterRow = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId("Total Boosters")
.setLabel("Total Boosters")
.setEmoji("988797857907769374")
.setStyle(ButtonStyle.Primary)
);
// Executes when member boost the server and received the "Nitro Boost" role.
if (
!oldMember.roles.cache.has(
newMember.guild.roles.premiumSubscriberRole?.id
) &&
newMember.roles.cache.has(newMember.guild.roles.premiumSubscriberRole?.id)
) {
const boostAnnounceEmbed = new EmbedBuilder()
.setAuthor({
name: `Congratulations we have new booster!`,
iconURL: newMember.guild.iconURL({ size: 1024 }),
})
.setDescription(
`>>> Dear ${newMember}, You are really awesome and amazing.\nThanks for boosting our server, Enjoy your ${newMember.guild.roles.premiumSubscriberRole} role and other exclusive perks.`
)
.addFields({
name: "💎 Total Boost:",
value: `${newMember.guild.premiumSubscriptionCount} Boost | Community (${boostLevel})`,
inline: false,
})
.setImage(
"https://cdn.discordapp.com/attachments/997473822787780669/1235649668978053181/p1_3187142_731753fb_LE_auto_x2_result.png?ex=663523ee&is=6633d26e&hm=7d7f3b33acb09f05a277802035cf84b79f8982eb1d01c73d0e8e60a85c23af78&"
)
.setColor("F47FFF")
.setFooter({
text: `${newMember.guild.name} Boost Detection System`,
iconURL: newMember.user.displayAvatarURL({ size: 1024 }),
})
.setTimestamp();
const boostAnnounceRow = new ActionRowBuilder().addComponents(
totalBoosterRow.components[0],
new ButtonBuilder()
.setLabel(newMember.user.username)
.setEmoji("1301252005700042792")
.setCustomId("Disabled")
.setStyle(ButtonStyle.Danger)
.setDisabled(true)
);
const msg = await boostAnnounceChannel.send({
content: `${newMember} \`${newMember}\``,
embeds: [boostAnnounceEmbed],
components: [boostAnnounceRow],
});
// Adds a reaction emoji to the above sent message
msg.react("🥳");
// Sends DM with button to the NEW nitro booster
await newMember
.send({
embeds: [
new EmbedBuilder()
.setDescription(
`- Hello dear ${newMember}, You are really awesome. Thanks for boosting the **__${newMember.guild.name}__** server!\n- Please consider to enjoy your new **${newMember.guild.roles.premiumSubscriberRole?.name}** role and other massive perks 🎉`
)
.setColor(newMember.guild.members.me.displayHexColor)
.setFooter({
text: "Don't forget to click on the link button below for more info",
iconURL: newMember.user.displayAvatarURL({ size: 1024 }),
})
.setTimestamp(),
],
components: [
new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setLabel("Jump to boost message")
.setStyle(ButtonStyle.Link)
.setURL(msg.url)
),
],
})
.catch((err) => {
console.error(
`An error occurred while sending DM to new booster:\n-> ${chalk.red(
err
)}`
);
});
// Boost Announce Log System
const boostLogEmbed = new EmbedBuilder()
.setAuthor({
name: `NEW Boost Detection System`,
iconURL: client.user.displayAvatarURL(),
})
.addFields(
{
name: "💎 Nitro Booster",
value: `${newMember.user} (${newMember.user.username})`,
},
{
name: "🎉 Server Boost at",
value: `<t:${Math.round(
newMember.premiumSinceTimestamp / 1000
)}:D> (<t:${Math.round(newMember.premiumSinceTimestamp / 1000)}:R>)`,
inline: true,
},
{
name: "⏰ Account Created at",
value: `<t:${Math.round(
newMember.user.createdTimestamp / 1000
)}:D> (<t:${Math.round(newMember.user.createdTimestamp / 1000)}:R>)`,
inline: true,
},
{
name: "📆 Joined Server at",
value: `<t:${Math.round(
newMember.joinedTimestamp / 1000
)}:D> (<t:${Math.round(newMember.joinedTimestamp / 1000)}:R>)`,
inline: true,
},
{
name: "💜 Total Boost",
value: `${newMember.guild.premiumSubscriptionCount} Boost | Community (${boostLevel})`,
inline: false,
},
{
name: "✅ Assigned Role",
value: `${newMember.guild.roles.premiumSubscriberRole} (${newMember.guild.roles.premiumSubscriberRole?.id})`,
inline: false,
}
)
.setThumbnail(newMember.user.displayAvatarURL({ size: 1024 }))
.setColor(newMember.guild.members.me.displayHexColor)
.setFooter({
text: `Member ID: ${newMember.user.id}`,
iconURL: newMember.guild.iconURL({ size: 1024 }),
})
.setTimestamp();
boostAnnounceLogChannel.send({
embeds: [boostLogEmbed],
});
}
// Executes when member unboost the server and "Nitro Booster" was taken from him
if (
oldMember.roles.cache.has(
newMember.guild.roles.premiumSubscriberRole?.id
) &&
!newMember.roles.cache.has(newMember.guild.roles.premiumSubscriberRole?.id)
) {
// Sends DM with button to the NEW UnBooster
await oldMember
.send({
embeds: [
new EmbedBuilder()
.setDescription(
`Hello dear ${oldMember}, Unfortunately your nitro boost for **__${oldMember.guild.name}__** server has been expired and you lost your special and cool perks such as an exclusive **${oldMember.guild.roles.premiumSubscriberRole?.name}** role :'(`
)
.setColor(oldMember.guild.members.me.displayHexColor)
.setFooter({
text: "You can get all these perks back by boosting again 💫",
iconURL: oldMember.user.displayAvatarURL({ size: 1024 }),
})
.setTimestamp(),
],
})
.catch((err) => {
console.error(
`An error occurred while sending DM to the member who has unboost the server:\n-> ${chalk.red(
err
)}`
);
});
// Unboost Log System
const unboostEmbedLog = new EmbedBuilder()
.setAuthor({
name: `NEW UnBoost or Expired Detection System`,
iconURL: client.user.displayAvatarURL(),
})
.addFields(
{
name: "📌 UnBooster",
value: `${oldMember.user} (${oldMember.user.username})`,
},
{
name: "⏰ Account Created at",
value: `<t:${Math.round(
oldMember.user.createdTimestamp / 1000
)}:D> (<t:${Math.round(oldMember.user.createdTimestamp / 1000)}:R>)`,
inline: true,
},
{
name: "📆 Joined Server at",
value: `<t:${Math.round(
oldMember.joinedTimestamp / 1000
)}:D> (<t:${Math.round(oldMember.joinedTimestamp / 1000)}:R>)`,
inline: true,
},
{
name: "💜 Total Boost",
value: oldMember.guild.premiumSubscriptionCount
? `${oldMember.guild.premiumSubscriptionCount} Boost | Community (${boostLevel})`
: "No one has boosted this server.",
inline: false,
},
{
name: "❌ Removed Role",
value: `${oldMember.guild.roles.premiumSubscriberRole} (${oldMember.guild.roles.premiumSubscriberRole?.id})`,
inline: false,
}
)
.setThumbnail(oldMember.user.displayAvatarURL({ size: 1024 }))
.setColor(oldMember.guild.members.me.displayHexColor)
.setFooter({
text: `Member ID: ${oldMember.user.id}`,
iconURL: oldMember.guild.iconURL({ size: 1024 }),
})
.setTimestamp();
const unboostLogMessage = await boostAnnounceLogChannel.send({
embeds: [unboostEmbedLog],
components: oldMember.guild.premiumSubscriptionCount
? [totalBoosterRow]
: [],
});
// Pins the embed message which has send to the log channel
unboostLogMessage.pin();
}
});
client.on("interactionCreate", async (interaction) => {
if (!interaction.isButton()) return;
if (interaction.customId === "Total Boosters") {
await interaction.deferReply({ ephemeral: true });
// Calculates the number of members who has boost this server
const totalBoosters =
(await interaction.guild.members.fetch()) // Waiting for fetching all members at first
.filter((member) =>
member.roles.cache.has(
interaction.guild.roles.premiumSubscriberRole?.id
)
)
.map(
(member) =>
`- ${member} | ${
member.user.username
} | Last boost at: <t:${Math.round(
member.premiumSinceTimestamp / 1000
)}:D>`
)
.join("\n") || "❌ No booster was found for this server!";
const totalBoosterEmbed = new EmbedBuilder()
.setAuthor({
name: `All of the ${interaction.guild.name} boosters [${
interaction.guild.roles.premiumSubscriberRole?.members.size ?? 0
}]`, // Because all the members of this server are fetched first, This property returns a completely correct number regardless of how large it is.
iconURL: interaction.guild.iconURL({ size: 1024 }),
})
.setDescription(
totalBoosters.length > 4096
? totalBoosters.slice(0, 4093) + "..."
: totalBoosters
) // Ensures that the output always is equal or less than 4096 characters for prevent Discord limits
.setColor(interaction.guild.members.me.displayHexColor)
.setFooter({
text: `Requested by ${interaction.user.username}`,
iconURL: interaction.user.displayAvatarURL({ size: 1024 }),
})
.setTimestamp();
interaction.editReply({
embeds: [totalBoosterEmbed],
});
}
});
// Emitted when the client/bot become to online
client.on("ready", () => {
console.log(
chalk.green(`Successfully logged in as ${chalk.bold(client.user.tag)}`),
chalk.bold("\nGitHub Repository:"),
chalk.blueBright("https://github.com/CalledMasih/Boost-Unboost-Announcer"),
"- If is useful please don't forget to",
chalk.yellowBright("star⭐"),
chalk.bold("\nWebsite:"),
chalk.blueBright("https://calledmasih.ir")
);
});
// Logs in to your client by it's token
client.login(config.botToken);
/*
❓ Don't forget to filled out "config.json" file by your information and check the "README.md" file!
All of the methods have been carefully tested and without any bugs.
If you have any issues while using this source, feel free to contact me thorough my social media which is @CalledMasih
*/