-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
42 lines (37 loc) · 1.29 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
const { Client } = require('@twitchapis/twitch.js');
const env = require('dotenv').config();
const fs = require("fs");
const path = require('node:path');
let config = require("./config.json");
const client = new Client({
channels: config.channels,
});
let commandsLoader = {}
async function loadCommands() {
let commandes = [];
const commandsPaths = path.join(__dirname, 'twitch_commands');
const commandFiless = fs.readdirSync(commandsPaths).filter(file => file.endsWith('.js'));
for (const file of commandFiless) {
const filePath = path.join(commandsPaths, file);
const command = require(filePath);
let name = command.data.name;
commandes.push({ [name]: command })
console.log("commands => " + command.data.name + " 🆙");
commandes.forEach(e => {
Object.assign(commandsLoader, e)
})
}
}
loadCommands()
client.on('ready', e => {
console.log(`Logged in as ${client.user.name}!`);
});
client.on('message', async (msg) => {
rankSysteme.addXp(msg.author.id, msg)
let commandsName = msg.content.slice(1);
let searchCommands = commandsLoader.hasOwnProperty(commandsName);
if (searchCommands) {
commandsLoader[commandsName].runCommands(msg, client);
}
});
client.login(env.parsed.TOKEN.toString());