-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
111 lines (94 loc) · 3.01 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
require("dotenv").config();
const handleMessage = require("./message/message");
const { Client, GatewayIntentBits, Collection } = require("discord.js");
const { REST, Routes } = require("discord.js");
const { Manager } = require("erela.js");
const fs = require("node:fs");
const TOKEN = process.env.TOKEN;
const CLIENT_ID = process.env.CLIENT_ID;
const GUILD_ID = process.env.GUILD_ID;
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildPresences,
],
});
// Define some options for the node
const nodes = [
{
host: process.env.HOST,
password: process.env.PASS,
port: 443,
secure: true,
},
];
client.commands = new Collection();
const commands = [];
const commandFiles = fs
.readdirSync("./commands")
.filter((file) => file.endsWith(".js"));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.data.name, command);
commands.push(command.data.toJSON());
}
const rest = new REST({ version: "10" }).setToken(TOKEN);
(async () => {
try {
console.log(
`Started refreshing ${commands.length} application (/) commands`
);
await rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), {
body: commands,
});
} catch (error) {
console.error(error);
}
})();
client.on("ready", () => {
client.manager.init(client.user.id);
console.log(`Logged in as ${client.user.tag}!`);
});
client.on("interactionCreate", async (interaction) => {
if (!interaction.isChatInputCommand() || !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 error executing this command.",
ephemeral: true,
});
}
});
// 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));
//message
client.on("messageCreate", (message) => handleMessage(message, client));
client.login(TOKEN);