forked from ZeroDiscord/Giveaway
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
116 lines (112 loc) · 4.81 KB
/
index.js
File metadata and controls
116 lines (112 loc) · 4.81 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
const Discord = require("discord.js");
const client = new Discord.Client();
const fs = require("fs");
const config = require("./config.json");
client.config = config;
// Initialise discord giveaways
const { GiveawaysManager } = require("discord-giveaways");
client.giveawaysManager = new GiveawaysManager(client, {
updateCountdownEvery: 3000,
default: {
botsCanWin: false,
embedColor: "#FF0000",
reaction: "🎉"
}
});
//Coded by Zero
/* Load all events (discord based) */
fs.readdir("./events/discord", (_err, files) => {
files.forEach(file => {
if (!file.endsWith(".js")) return;
const event = require(`./events/discord/${file}`);
let eventName = file.split(".")[0];
console.log(`[Event] ✅ Loaded: ${eventName}`);
client.on(eventName, event.bind(null, client));
delete require.cache[require.resolve(`./events/discord/${file}`)];
});
});
// Let commands be a new collection
client.commands = new Discord.Collection();
/* Load all commands */
fs.readdir("./commands/", (_err, files) => {
files.forEach(file => {
if (!file.endsWith(".js")) return;
let props = require(`./commands/${file}`);
let commandName = file.split(".")[0];
client.commands.set(commandName, props);
console.log(`[Command] ✅ Loaded: ${commandName}`);
});
});
/* Client's GiveawaysManager Events */
client.giveawaysManager.on(
"giveawayReactionAdded",
async (giveaway, reactor, messageReaction) => {
if (reactor.user.bot) return;
try {
if(giveaway.extraData){
await client.guilds.cache.get(giveaway.extraData.server).members.fetch(reactor.id)
}
reactor.send(
new Discord.MessageEmbed()
.setTimestamp()
.setTitle("Entery Approved! | You have a chance to win!!")
.setDescription(
`Your entery to [This Giveaway](https://discord.com/channels/${giveaway.guildID}/${giveaway.channelID}/${giveaway.messageID}) has been approved!`
)
.setFooter("Subscribe to ZeroSync on YT!")
.setTimestamp()
);
} catch (error) {
const guildx = client.guilds.cache.get(giveaway.extraData.server)
messageReaction.users.remove(reactor.user);
reactor.send( new Discord.MessageEmbed()
.setTimestamp()
.setTitle(":x: Entery Denied | Databse Entery Not Found & Returned!")
.setDescription(
`Your entery to [This Giveaway](https://discord.com/channels/${giveaway.guildID}/${giveaway.channelID}/${giveaway.messageID}) has been denied as you did not join **${guildx.name}**`
)
.setFooter("Subscribe to ZeroSync on YT!")
);
}
}
);
// Check if user reacts on an ended giveaway
client.giveawaysManager.on('endedGiveawayReactionAdded', (giveaway, member, reaction) => {
reaction.users.remove(member.user);
member.send(`**Aw snap! Looks Like that giveaway has already ended!**`)
});
// Dm our winners
client.giveawaysManager.on('giveawayEnded', (giveaway, winners) => {
winners.forEach((member) => {
member.send(new Discord.MessageEmbed()
.setTitle(`🎁 Let's goo!`)
.setDescription(`Hello there ${member.user}\n I heard that you have won **[[This Giveaway]](https://discord.com/channels/${giveaway.guildID}/${giveaway.channelID}/${giveaway.messageID})**\n Good Job On Winning **${giveaway.prize}!**\nDirect Message the host to claim your prize!!`)
.setTimestamp()
.setFooter(member.user.username, member.user.displayAvatarURL())
);
});
});
// Dm Rerolled winners
client.giveawaysManager.on('giveawayRerolled', (giveaway, winners) => {
winners.forEach((member) => {
member.send(new Discord.MessageEmbed()
.setTitle(`🎁 Let's goo! We Have A New Winner`)
.setDescription(`Hello there ${member.user}\n I heard that the host rerolled and you have won **[[This Giveaway]](https://discord.com/channels/${giveaway.guildID}/${giveaway.channelID}/${giveaway.messageID})**\n Good Job On Winning **${giveaway.prize}!**\nDirect Message the host to claim your prize!!`)
.setTimestamp()
.setFooter(member.user.username, member.user.displayAvatarURL())
);
});
});
// When They Remove Reaction
client.giveawaysManager.on('giveawayReactionRemoved', (giveaway, member, reaction) => {
return member.send( new Discord.MessageEmbed()
.setTimestamp()
.setTitle('❓ Hold Up Did You Just Remove a Reaction From A Giveaway?')
.setDescription(
`Your entery to [This Giveaway](https://discord.com/channels/${giveaway.guildID}/${giveaway.channelID}/${giveaway.messageID}) was recorded but you un-reacted, since you don't need **${giveaway.prize}** I would have to choose someone else 😭`
)
.setFooter("Think It was a mistake? Go react again!")
);
});
// Login through the client
client.login(config.token);