-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexample.js
364 lines (344 loc) · 9.96 KB
/
example.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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
require("dotenv").config();
const {
Client,
GatewayIntentBits,
ApplicationCommandType,
ApplicationCommandOptionType,
Colors,
EmbedBuilder,
} = require("discord.js");
const { Manager } = require("./index");
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent,
],
});
// // for custom embed
// class CustomManager extends Manager {
// GiveawayStartEmbed(giveaway) {
// let embed = new EmbedBuilder().setTitle(`Giveway Started`);
// return embed;
// }
// GiveawayEndNoWinnerEmbed(giveaway) {
// let embed = new EmbedBuilder().setTitle(`Giveway Ended No Winner`);
// return embed;
// }
// GiveawayEndWinnerEmbed(giveaway) {
// let embed = new EmbedBuilder().setTitle(`Giveway Ended Winners`);
// return embed;
// }
// }
// const manager = new CustomManager(client, {
// embedColor: Colors.Blurple,
// pingEveryone: true,
// });
const manager = new Manager(client, {
embedColor: Colors.Blurple,
pingEveryone: false,
emoji: "🎁",
});
client.on("ready", () => {
console.log("bot is ready !!");
const commands = [
{
name: "delete",
description: `delete giveaway`,
type: ApplicationCommandType.ChatInput,
options: [
{
name: "messageid",
description: `give message id of giveaway`,
type: ApplicationCommandOptionType.String,
required: true,
},
],
},
{
name: "edit",
description: `edit giveaway`,
type: ApplicationCommandType.ChatInput,
options: [
{
name: "messageid",
description: `give message id of giveaway`,
type: ApplicationCommandOptionType.String,
required: true,
},
{
name: "prize",
description: `give Prize of giveaway`,
type: ApplicationCommandOptionType.String,
required: true,
},
{
name: "wincount",
description: `give Winner Count of giveaway`,
type: ApplicationCommandOptionType.String,
required: true,
},
],
},
{
name: "end",
description: `end giveaway`,
type: ApplicationCommandType.ChatInput,
options: [
{
name: "messageid",
description: `give message id of giveaway`,
type: ApplicationCommandOptionType.String,
required: true,
},
],
},
{
name: "reroll",
description: `reroll giveaway`,
type: ApplicationCommandType.ChatInput,
options: [
{
name: "messageid",
description: `give message id of giveaway`,
type: ApplicationCommandOptionType.String,
required: true,
},
],
},
{
name: "start",
description: `start giveaway`,
type: ApplicationCommandType.ChatInput,
options: [
{
name: "channel",
description: `channel`,
type: ApplicationCommandOptionType.Channel,
required: true,
},
{
name: "prize",
description: `prize`,
type: ApplicationCommandOptionType.String,
required: true,
},
{
name: "winnercount",
description: `winnerCount`,
type: ApplicationCommandOptionType.Number,
required: true,
},
{
name: "duration",
description: `duration`,
type: ApplicationCommandOptionType.String,
required: true,
},
],
},
{
name: "deleteall",
description: `delete all`,
type: ApplicationCommandType.ChatInput,
},
{
name: "ping",
description: `check bot ping`,
type: ApplicationCommandType.ChatInput,
},
];
client.guilds.cache.get("903532162236694539")?.commands.set(commands);
manager.connect(
"mongodb+srv://tofey16500:[email protected]/giveaways"
);
});
client.on("interactionCreate", async (interaction) => {
await interaction.deferReply({ ephemeral: true }).catch((e) => {});
if (interaction.isChatInputCommand()) {
// code
const cmdName = interaction.commandName;
switch (cmdName) {
case "start":
{
const channel = interaction.options.getChannel("channel");
const prize = interaction.options.getString("prize");
const winnerCount = interaction.options.getNumber("winnercount");
const duration = interaction.options.getString("duration");
interaction.followUp({
content: `Giveaway Started`,
ephemeral: true,
});
manager
.start(interaction, {
channel: channel,
duration: duration,
prize: prize,
winnerCount: winnerCount,
})
.catch((e) => {
console.log(e);
});
}
break;
case "deleteall":
{
const data = await manager.deleteall(interaction.guildId);
interaction.followUp({
content: `${data?.deleted} Giveaways Deleted`,
});
}
break;
case "delete":
{
let messageId = interaction.options.getString("messageid", true);
let deleted = await manager.deleteGiveaway(messageId);
interaction.followUp({
content: `Giveaway ${deleted ? "Deleted" : "Not Deleted"}`,
});
}
break;
case "edit":
{
let messageId = interaction.options.getString("messageid", true);
let prize = interaction.options.getString("prize", true);
let wincount = interaction.options.getString("wincount", true);
let edited = await manager.editGiveaway(messageId, {
prize: prize,
winCount: wincount,
});
if (edited) {
interaction.followUp({
content: `Giveaway Edited`,
});
} else {
interaction.followUp({
content: `Invalid Giveaway`,
});
}
}
break;
case "reroll":
{
let messageId = interaction.options.getString("messageid", true);
let rerolled = await manager.rerollGiveaway(messageId);
if (rerolled) {
interaction.followUp({
content: `Giveaway Rerolled`,
});
} else {
interaction.followUp({
content: `Invalid Giveaway`,
});
}
}
break;
case "end":
{
let messageId = interaction.options.getString("messageid", true);
let ended = await manager.endGiveaway(messageId);
if (ended) {
interaction.followUp({
content: `Giveaway Ended`,
});
} else {
interaction.followUp({
content: `Invalid Giveaway`,
});
}
}
break;
case "ping":
{
return interaction.followUp({
content: `Pong :: \`${client.ws.ping}\``,
ephemeral: true,
});
}
break;
default:
break;
}
}
});
let embed = new EmbedBuilder().setColor("Blurple");
manager.on("GiveawayReady", (name) => {
console.log(`${name} is Ready`);
});
// manager.on("GiveawayStarted", (message, giveaway) => {
// // console.log("GiveawayStarted");
// message
// .reply({
// embeds: [embed.setDescription(`Giveaway Started`)],
// })
// .then((msg) => {
// setTimeout(() => {
// msg.delete().catch((e) => {});
// }, 3000);
// });
// });
manager.on("GiveawayWinner", (message, giveaway) => {
let Gwinners = giveaway.winners
.map((winner) => `<@${winner.userID}>`)
.join(", ");
message.channel?.send({
content: `${Gwinners}`,
embeds: [
embed.setDescription(
`${Gwinners} Won The \`${giveaway.prize}\` Giveaway Prize. Hosted By <@${giveaway.hostedBy}>`
),
],
});
giveaway.winners.map(async (user) => {
const u = await message.guild.members.fetch(user.userID);
u.send({
embeds: [
embed.setDescription(
`You Won The Giveaway [\`Giveaway Link\`](${message.url})`
),
],
});
});
});
manager.on("GiveawayRerolled", (message, giveaway) => {
// console.log("GiveawayRerolled");
message.reply({
embeds: [embed.setDescription(`\`${giveaway.prize}\` Giveaway Rerolled`)],
});
});
manager.on("NoWinner", (message, giveaway) => {
message.reply({
embeds: [embed.setDescription(`No One Won ${giveaway.prize}`)],
});
});
manager.on("InvalidGiveaway", (member, giveaway) => {
member.send({
embeds: [embed.setDescription(`You are Joining in Ended Giveaway`)],
});
});
manager.on("UserJoinGiveaway", (member, giveaway) => {
member.send({
embeds: [embed.setDescription(`You Joined ${giveaway.prize} Giveaway`)],
});
});
manager.on("UserLeftGiveaway", (member, giveaway) => {
member.send({
embeds: [embed.setDescription(`You Left ${giveaway.prize} Giveaway`)],
});
});
client.login(
"MTEzMjEyNDk4MjgwNjMzNTUxOA.Gb6Tha.Zh--HNmVZwDXo3bA3WYBBV7tyKEsRWs9LW9Ym8"
);
process.on("unhandledRejection", (reason, p) => {
console.log(" [Error_Handling] :: Unhandled Rejection/Catch");
console.log(reason, p);
});
process.on("uncaughtException", (err, origin) => {
console.log(" [Error_Handling] :: Uncaught Exception/Catch");
console.log(err, origin);
});
process.on("uncaughtExceptionMonitor", (err, origin) => {
console.log(" [Error_Handling] :: Uncaught Exception/Catch (MONITOR)");
console.log(err, origin);
});