This repository has been archived by the owner on Sep 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
127 lines (96 loc) · 4.74 KB
/
bot.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
const discord = require('discord.js');
const fs = require('fs');
const process = require('process');
const client = new discord.Client({presence: {status: 'online', activity: {type: 'LISTENING', name: 'k.help | v2.1'}}});
client.commands = new discord.Collection();
client.color = (0x70e1df);
client.start_time = Date.now()
client.prefix = "k.";
client.players = new discord.Collection();
client.broadcast = client.voice.createBroadcast()
const folders = fs.readdirSync('./commands')
for (const folder of folders) {
const files = fs.readdirSync(`./commands/${folder}`).filter(file => file.endsWith('.js'));
for (const file of files) {
const command = require(`./commands/${folder}/${file}`);
client.commands.set(command.name, command);
}
}
async function play() {
const songs = fs.readdirSync('./songs');
const index = Math.floor(Math.random() * songs.length);
const song = songs[index];
client.current = song.slice(0, -4);
const embed = new discord.MessageEmbed()
.setTitle('Now Playing')
.setDescription(`${client.current}`)
.setColor(client.color)
.setFooter(`Use ${client.prefix}help for more commands!`, `${client.user.avatarURL()}`);
if (client.players.size > 0) {
client.players.each(async player => player.controller = await player.channel.send(embed))
}
client.broadcast.play(`./songs/${song}`)
.on('finish', async () => {
if (client.players.size > 0) {
client.players.each(async player => await player.controller.delete())
}
await play();
});
}
client.on('ready', async () => {
console.log(`${client.user.tag} is online and serving ${client.guilds.cache.size} guilds`);
await play();
});
client.on('message', async message => {
if (!message.content.startsWith(client.prefix) || message.author.bot) return;
const args = message.content.slice(client.prefix.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase();
const command = client.commands.get(commandName) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
if (!command) return;
if (command.ownerOnly && message.author.id != '313314995687391234') return;
try {
await command.execute(message, args);
} catch(error) {
console.error(error);
await message.channel.send('🛑 An unexpected error occurred while executing the command! Please report this to the owner. \n```' + error + '```')
}
});
client.on('guildCreate', async guild => {
let channel = guild.channels.cache.find(channel => channel.type === 'text' && channel.permissionsFor(guild.me).has('SEND_MESSAGES'))
const embed = new discord.MessageEmbed()
.setTitle('Thank you for inviting Kanye Reloaded!')
.setDescription('You can start playing Kanye music by typing **kanye join** while in a voice channel. \n\nDo **kanye help** for more information on how to do any commands\n\n If you have any issues/question, feel free to join our [support server](https://discord.gg/bBeAQcftAr)')
.setColor(client.color)
.setFooter(`Use ${client.prefix}help for more commands!`, `${client.user.avatarURL()}`);
await channel.send(embed);
channel = await client.channels.fetch('799402132105068545')
await channel.send(`<@313314995687391234>, I was added to **${guild.name}**! I'm now in **${client.guilds.cache.size}** guilds.`)
});
client.on('guildDelete', async guild => {
const channel = await client.channels.fetch('799402132105068545')
await channel.send(`<@313314995687391234>, I was removed from **${guild.name}**. I'm now in **${client.guilds.cache.size}** guilds.`)
});
client.on('voiceStateUpdate', async (oldState, newState) => {
if (newState.member === newState.guild.me && !newState.connection && !client.players.get(oldState.guild.id).maybe_disconnect) {
const player = client.players.get(oldState.guild.id);
console.log('Detected forced disconnect, cleaning up...');
try {
await player.controller.delete();
} catch (err) {}
client.players.delete(player.message.guild.id);
}
})
process.on('SIGINT', async () => {
if (client.players.size > 0) {
for (const player of client.players.values()) {
player.maybe_disconnect = true;
player.voice.disconnect();
await player.controller.delete();
await player.channel.send(`⚠️ <@${player.dj.id}>, the bot is being manually restarted by the owner. Once the bot has restarted, you can use \`${client.prefix}join\` to rejoin the bot.`);
client.players.delete(player.message.guild.id);
}
}
console.log('Shutting down now...');
process.exit();
});
client.login('token here');