forked from fdciabdul/tmuxdcbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
110 lines (101 loc) · 3.11 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
const Discord = require("discord.js");
const fs = require("fs");
const config = require("./config");
const banner = require("ascii-art");
require("dotenv").config();
var clc = require("cli-color");
const client = new Discord.Client();
client.queues = new Discord.Collection();
client.commands = new Discord.Collection();
const commands = fs
.readdirSync(__dirname + "/commands")
.filter((file) => file.endsWith(`.js`));
commands.forEach((command) => {
const comand = require(__dirname + `/commands/${command}`);
if (comand.name) {
client.commands.set(comand.name, comand);
}
});
var figlet = require('figlet');
figlet.text("fdciabdul!", {
font: 'Ghost',
horizontalLayout: 'default',
verticalLayout: true,
width: 150,
whitespaceBreak: true
}, function(err, data) {
if (err) {
console.log('Something went wrong...');
console.dir(err);
return;
}
console.log(data);
});
client.on("ready", () => {
console.log(clc.green(`
Ready to start ! ${client.user.tag}
dont forget to subscribe fdciabdul channel :)
`));
client.user.setPresence({
activity: {
name: `*help | ${client.guilds.cache.size} servers`,
type: "LISTENING",
},
status: "online",
});
});
client.on("message", async (message) => {
console.log(clc.red("New Message = > "+ message.content));
if (message.author.bot || !message.guild || !message.content.startsWith(config.prefix))
return;
if (!message.member.voice.channel && message.content !== ("!h" || "!help"))
return message.channel.send("❌ You're not in a voice channel.");
const args = message.content.slice(1).trim().split(/ +/g);
const command = args.shift().toLowerCase();
const cmd =
client.commands.get(command) ||
client.commands.find((cmd) => cmd.aliases && cmd.aliases.includes(command));
if (!cmd) return;
try {
cmd.run(message, args, client);
} catch (error) {
console.log(error);
}
});
client.on("voiceStateUpdate", (oldState, newState) => {
let queue = client.queues.find((g) => g.guildID === oldState.guild.id);
if (!queue) return;
if (newState.member.id === client.user.id && !newState.channelID) {
queue.dispatcher.destroy();
queue.stream.destroy();
client.queues.delete(newState.guild.id);
}
if (
queue.voiceConnection &&
queue.voiceConnection.channel.members.array().length <= 1
) {
setTimeout(() => {
if (
queue.voiceConnection &&
queue.voiceConnection.channel.members.array().length <= 1
) {
queue.dispatcher.destroy();
queue.voiceConnection.dispatcher.destroy();
queue.voiceConnection.channel.leave();
queue.stream.destroy();
client.queues.delete(message.guild.id);
queue.firstMessage.channel
.send({
embed: {
color: 0x51cab0,
title: "I was innactive for too long.",
description: "Bye",
},
})
.then((m) => m.react("👋"));
}
}, 50000);
}
queue = null;
});
client.login(config.TOKEN);