-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
103 lines (84 loc) · 3.17 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
const { Client, Collection, GatewayIntentBits } = require('discord.js');
const { REST, Routes } = require('discord.js');
const { Manager } = require("erela.js");
const config = require('./config.json');
const fs = require('node:fs');
//const path = require('node:path');
const client = new Client({
intents: [GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMembers]
});
client.commands = new Collection();
const commands = [];
// Grab all the command files from the commands directory you created earlier
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.data.name, command);
commands.push(command.data.toJSON());
}
// Construct and prepare an instance of the REST module
const rest = new REST({ version: '10' }).setToken(config.token);
// and deploy your commands!
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);
// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationGuildCommands(config.clientId, config.guildId),
{ body: commands },
);
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();
client.once("ready", () => {
client.manager.init(client.user.id);
console.log('Ready!');
});
client.on("interactionCreate", (interaction) => {
if(!interaction.isCommand()) return;
const command = client.commands.get(interaction.commandName)
if (!command) return;
try {
command.execute(client,interaction)
} catch (error) {
interaction.reply({content:"There was an error executing this command.", ephemeral:true})
}
});
// Erela.js -> music manager
// Define some options for the node
const nodes = [
// If you pass a object like so the "host" property is required
{
host: "localhost", // Optional if Lavalink is local
port: 2333, // Optional if Lavalink is set to default
password: "youshallnotpass", // Optional if Lavalink is set to default
},
];
// Assign Manager to the client variable
client.manager = new Manager({
// The nodes to connect to, optional if using default lavalink options
nodes,
// Method to send voice data to Discord
send: (id, payload) => {
const guild = client.guilds.cache.get(id);
// NOTE: FOR ERIS YOU NEED JSON.stringify() THE PAYLOAD
if (guild) guild.shard.send(payload);
}
});
// Emitted whenever a node connects
client.manager.on("nodeConnect", node => {
console.log(`Node "${node.options.identifier}" connected.`)
})
// Emitted whenever a node encountered an error
client.manager.on("nodeError", (node, error) => {
console.log(`Node "${node.options.identifier}" encountered an error: ${error.message}.`)
})
// THIS IS REQUIRED. Send raw events to Erela.js
client.on("raw", d => client.manager.updateVoiceState(d));
client.login(config.token);