-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
74 lines (54 loc) · 1.48 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
/*
* using discord.js v12.5.3
* make by Vins 2106
* please give me a credit if you want use this :)
*/
// process .env
require("dotenv").config();
// config
const config = {
token: process.env.TOKEN,
channel: process.env.CHANNEL
};
// bot
const Discord = require("discord.js");
const client = new Discord.Client({
disableMentions: "everyone"
});
let { Collection } = require("discord.js");
let MUSIC = new Collection();
let ytdl = require("ytdl-core")
let channel;
// login as bot
client.login(config.token);
// events
client.on("ready", () => {
console.log("[BOT] ready to 24/7 :)");
channel = client.channels.cache.get(config.channel);
if (!channel) return console.log("Invalid channel.");
if (!channel.type === "voice") return console.log("Invalid channel.");
handle()
});
client.on("voiceStateUpdate", async (oldV, newV) => {
if (newV.member.id !== client.user.id) return;
if (oldV.channel.id == channel.id && !newV.channel) {
handle()
}
});
async function handle() {
if (!channel) return console.log("Invalid channel.");
if (!channel.type === "voice") return console.log("Invalid channel.");
let Struct = {
vc: channel,
c: await channel.join()
}
play()
async function play() {
const dispatcher = Struct.c.play(ytdl('https://www.youtube.com/watch?v=5qap5aO4i9A'))
.on('finish', () => {
play();
})
.on('error', error => console.error(error));
dispatcher.setVolumeLogarithmic(100 / 100);
}
}