-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
180 lines (163 loc) · 5.53 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
const express = require('express');
const app = express();
const port = 3000;
app.get('/', (req, res) => res.send('Hello World!'));
app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`));
const Discord = require("discord.js")
const ytdl = require("ytdl-core")
const mongoose = require('mongoose');
const disord = require('discord-reply');
const ani = require('./schema/NfsGuildSchema')
const radio = new Discord.Client()
const mongodburi = "Your cluster link here"
const log = "";
const link = "https://www.youtube.com/watch?v=7G7umMPwlO4";
const reset = new Discord.MessageEmbed()
.setColor('ORANGE')
.setTitle('Restarting Song...')
.setFooter('A bot by DORTROX-');
mongoose.connect(process.env.mongodburi, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then((m) => {
console.log("Connected to DB");
})
.catch((err) => console.log(err));
radio.on('guildCreate', async (guild) => {
let defaultChannel = "";
guild.channels.cache.forEach((channel) => {
if (channel.type == "text" && defaultChannel == "") {
if (channel.permissionsFor(guild.me).has("SEND_MESSAGES")) {
defaultChannel = channel;
}
}
})
//defaultChannel will be the channel object that it first finds the bot has permissions for
defaultChannel.send(`Hello @everyone, I'm NFS Live. Thanks for inviting me, Use $Nlive "voiceChannel_id" to set me up`, {
embed: {
title: 'Our Server',
url: 'https://discord.gg/SM22ddTSRr',
color: 0x2471a3,
description: "If need any help or wanna help us on other projects then join our server. ",
footer: {
text: 'D O R T R O 乂.'
}
}
});
const guildID = guild.id;
ani.create({
vcID: 'null',
guildID: guildID,
});
});
radio.on("guildDelete", async (guild) => {
const guildID = guild.id;
await ani.findOneAndDelete({ guildID: guildID });
})
const prefix = "$Nlive";
radio.on("message", async message => {
if (!message.content.startsWith(prefix)) return;
const args = message.content
.slice(prefix.length)
.trim()
.split(/ +/g);
const index = message.content.indexOf(" ");
const vcid = message.content.slice(index + 1);
const doc = await ani.findOne({ guildID: message.guild.id });
try {
const update = { vcID: vcid };
await doc.updateOne(update);
message.lineReply("Your vc setup is successfully completed!");
} catch (err) {
console.log(err);
message.lineReply("Setup cancelled")
}
const loc = await ani.findOne({ guildID: message.guild.id });
radio.channels.cache.get(loc.vcID).join().then(connection => {
function play(connection) {
connection.voice.setSelfDeaf(true);
const stream = ytdl(link, { filter: "audio" })
const dispatcher = connection.play(stream)
dispatcher.on("finish", () => {
play(connection)
})
}
play(connection)
}).catch(e => {
const error = new Discord.MessageEmbed()
.setColor('RED')
.setTitle('Error Table')
.setDescription('```js\n' + e + '\n```')
.setFooter(`${radio.user.tag}`);
if (log){
radio.channels.cache.get(log).send(error)
}
})
})
radio.on("ready", async () => {
console.log(`Logged in as ${radio.user.tag}`)
radio.user.setActivity("NFS MUSIC", {
type: "STREAMING",
url: "https://www.twitch.tv/dortrox"
});
const guilds = await ani.find();
let arr = [];
for (const i in guilds) {
let pft = arr.push(guilds[i].vcID)
}
for (let i = 0; i < arr.length; i++) {
if (arr[i] === "null") return;
radio.channels.cache.get(arr[i]).join().then(connection => {
function play(connection) {
connection.voice.setSelfDeaf(true);
const stream = ytdl(link, { filter: "audio" })
const dispatcher = connection.play(stream)
dispatcher.on("finish", () => {
play(connection)
})
}
play(connection)
}).catch(e => {
const error = new Discord.MessageEmbed()
.setColor('RED')
.setTitle('Error Table')
.setDescription('```js\n' + e + '\n```')
.setFooter(`${radio.user.tag}`);
if (log){
radio.channels.cache.get(log).send(error)
}
})
};
// radio.on('voiceStateUpdate', (oldState, newState) => {
// //If a user join vc user will get a greeting message in log channel.
// let name = newState.id;
// if(newState.channelID == vc) {
// radio.channels.cache.get(log).send(`Thanks for joining <@${name}>. I hope you enjoy`)
// }
// //Prolly useless but prefer keeping it If a new user join channel Bot will start playing song.
// if (oldState.member.user.bot) return;
// if (oldState.member.user) return;
// voiceChannel.join().then(connection => {
// console.log("Joined voice channel")
// function play(connection) {
// connection.voice.setSelfDeaf(true);
// const stream = ytdl(link, { filter: "audio" })
// const dispatcher = connection.play(stream)
// dispatcher.on("finish", () => {
// play(connection)
// radio.channels.cache.get(log).send(reset)
// })
// }
// play(connection)
// }).catch(e => {
// const error = new Discord.MessageEmbed()
// .setColor('RED')
// .setTitle('Error Table')
// .setDescription('```js\n' + e + '\n```')
// .setFooter('DORTROX');
// radio.channels.cache.get(log).send(error)
// });
// })
})
radio.login(process.env.token);