forked from YashSaini99/Rex_RotH
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
152 lines (135 loc) · 4.75 KB
/
index.js
File metadata and controls
152 lines (135 loc) · 4.75 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
const Discord = require("discord.js");
const linereply = require("discord-reply");
const colors = require("colors")
const mongoose = require("mongoose");
const { MessageEmbed } = require('discord.js')
const getprefix = require("./util/getprefix");
const client = new Discord.Client({
presence: {
status: "dnd",
activity: {
name: `>Help`,
type: "LISTENING"
}
}
});
client.config = require("./config.json");
client.login(client.config.token);
client.on("ready", async () => {
console.log(`${client.user.tag} is now Online! Prefix: ${client.config.prefix}`);
await mongoose.connect(
client.config.mongourl,
{
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true
}
);
});
mongoose.connection.on("connected", () => {
console.log("Mongoose has successfully connected!");
});
// send msg if successfull connection to mongodb
mongoose.connection.on("err", err => {
console.error(`Mongoose connection error: \n${err.stack}`);
});
// send msg if error on connection
mongoose.connection.on("disconnected", () => {
console.warn("Mongoose connection lost");
});
//send msg if connection lost to mongodb
require("./logger")(client);
//const logger = require("./logger");
//logger(client)
client.commands = new Discord.Collection();
client.aliases = new Discord.Collection();
["command"].forEach(handler => {
require(`./handlers/${handler}`)(client)
})
//=========================================================================================================
client.queue = new Map()
const DisTube = require('distube')
client.distube = new DisTube(client, { searchSongs: false, emitNewSongOnly: true });
client.distube
.on('playSong', (message, queue, song) => {
message.channel.send({
embed: {
description: ` ***Playing*** _${song.name}_`,
color: "88b7f5"
}
});
})
.on("addSong", (message, queue, song) => {
message.channel.send({
embed: {
description: ` ***Added*** _${song.name}_ , _to the Queue_`,
color: "88b7f5"
}
})
})
.on("empty", (message) => {
message.channel.send({
embed: {
description: ` leaving the Voice Channel`,
color: '88b7f5'
}
})
})
//==========================================================================================================
const { GiveawaysManager } = require('discord-giveaways');
client.giveawaysManager = new GiveawaysManager(client, {
storage: "./database.json",
updateCountdownEvery: 5000,
default: {
botsCanWin: false,
embedColor: "f7f0f0",
reaction: "🎉"
}
});
// We now have a client.giveawaysManager property to manage our giveaways!
client.giveawaysManager.on("giveawayReactionAdded", (giveaway, member, reaction) => {
console.log(`${member.user.tag} entered giveaway #${giveaway.messageID} (${reaction.emoji.name})`);
});
client.giveawaysManager.on("giveawayReactionRemoved", (giveaway, member, reaction) => {
console.log(`${member.user.tag} unreact to giveaway #${giveaway.messageID} (${reaction.emoji.name})`);
});
client.giveawaysManager.on("giveawayEnded", (giveaway, winners) => {
console.log(`Giveaway #${giveaway.messageID} ended! Winners: ${winners.map((member) => member.user.username).join(', ')}`);
});
//==========================================================================================================
client.on('message', async (message) => {
if (message.author.bot) return;
const prefix = await getprefix(message.guild.id);
if(message.content === '<@788274414260322314>' || message.content === "<@!788274414260322314>"){
return message.lineReplyNoMention(`My Prefix for ${message.guild.name} is \`${prefix}\``)
}
if (!message.guild) return;
if (!message.content.startsWith(prefix)) return;
if (!message.member) message.member = await message.guild.fetchMember(message);
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const cmd = args.shift().toLowerCase();
if (cmd.length === 0) return;
let command = client.commands.get(cmd);
if (!command) command = client.commands.get(client.aliases.get(cmd));
if (command)
command.run(client, message, args);
});
client.on('guildCreate', (guild) => {
let channelToSend;
guild.channels.cache.forEach((channel) => {
if(
channel.type === 'text' &&
!channelToSend &&
channel.permissionsFor(guild.me).has("SEND_MESSAGES")
) channelToSend = channel;
});
if(!channelToSend) return;
channelToSend.send(
new MessageEmbed()
.setAuthor(`${client.user.username}` , client.user.displayAvatarURL())
.setDescription(`Thanks for Inviting me , My default Prefix is \`>\` but you can change it by using \`setprefix\` command `)
.setColor("WHITE")
.setTimestamp()
)
})