-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
164 lines (129 loc) · 5.08 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
// import requirements
const {
Client,
Intents,
MessageEmbed,
} = require('discord.js');
// starting in djs v13, we are required to specify which intents we are using in the client constructor
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_VOICE_STATES]
});
const vars = require('./variables.json');
const { getVoiceConnections } = require('@discordjs/voice');
const dotenv = require('dotenv');
// import config IDs
dotenv.config()
const TOKEN = process.env.TOKEN
/*
HTTP
*/
const http = require("http");
const port = 8080;
const requestListener = function (req, res) {
res.writeHead(200);
res.end("<html><head></head><body><p>test</p></body></html>");
};
const server = http.createServer(requestListener);
server.listen(port, () => {
console.log(`Server is running on ${port}`);
});
//
var cache = new Map();
const audio = new Map();
const startup = require('./src/startup');
// run this script upon starting up the bot and pass in the client
startup(client, cache, audio)
client.on('interactionCreate', async (interaction) => {
// if the interaction is a command
if (interaction.isCommand()) {
const command = client.commands.get(interaction.commandName);
const commandName = interaction.commandName;
if (!command) return;
console.log(command);
// checking if the cmd given is a music command 🎵
if (commandName == 'join' || commandName == 'leave' || commandName == 'play' || commandName == 'skip' || commandName == 'loop' || commandName == 'queue' || commandName == 'nowplaying' || commandName == 'shuffle' || commandName == 'pause' || commandName == 'unpause' || commandName == 'lyrics') {
// checking if a queue exists, if it doesn't, we make a queue
let serverQueue = cache.get(interaction.guild.id);
if (!serverQueue) {
let queue = {
vc: undefined,
connection: undefined,
songs: [],
loop: false,
autoplay: false
}
cache.set(interaction.guild.id, queue);
}
if (!interaction.member.voice.channel) {
let emb = new MessageEmbed()
.setAuthor({ name: "You need to be in a voice channel to run this command", iconURL: interaction.member.user.avatarURL(), url: 'https://discord.gg/Rkq2f3b8Tn' })
.setColor(vars.dangerColour)
await interaction.reply({ embeds: [emb] })
return;
}
}
try {
await interaction.deferReply();
try {
return await command.execute(client, interaction, cache, audio);
} catch (error) {
console.log("\n" + error);
}
} catch (err) {
if (err) console.log(err);
}
} else if (interaction.isButton()) {
try {
console.log("Interaction ran was a button");
const buttonID = await interaction.component.customId;
console.log(buttonID);
const file = await require(`./buttons/${buttonID}`);
console.log("File is " + file);
await file.execute(client, interaction, cache, audio);
} catch (e) {
console.log(e);
}
} else if (interaction.isAutocomplete()) {
let serverQueue = cache.get(interaction.guild.id);
let songs = serverQueue.songs;
const choices = [];
for (let i = 0; i < songs.length; i++) {
console.log("Song is " + songs[i]);
choices.push(songs[i].video_details.title);
}
console.log("Choices are " + choices);
const focusedValue = interaction.options.getFocused();
const filtered = choices.filter(choice => choice.startsWith(focusedValue));
await interaction.respond(
filtered.map(choice => ({ name: choice, value: choice })),
);
}
});
/*
Owner commands :)
I know they're really badly made but eh... only person seeing em is me, right?
*/
client.on("messageCreate", async(message) => {
if (!message.author.id === '422603238936936450') return;
if (message.content == '-guilds') {
message.channel.send("\`\`\`" + client.guilds.cache.size.toString() + "\`\`\`");
}
if (message.content == '-players') {
let connectionsMap = getVoiceConnections();
console.log(connectionsMap.size);
message.channel.send("\`\`\`Connections " + connectionsMap.size.toString() + "\nPlayers " + audio.size.toString() + "\`\`\`");
}
if (message.content == '-members') {
const members = client.guilds.cache.reduce((acc, guild) => acc + guild.memberCount, 0);
console.log(members);
message.channel.send(members.toString());
}
if (message.content == 'are you work') {
message.channel.send("yes.");
}
if (message.content == '-say') {
await message.delete();
await message.channel.send(message.content);
}
});
client.login(TOKEN);