-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommandHandler.js
More file actions
29 lines (28 loc) · 860 Bytes
/
commandHandler.js
File metadata and controls
29 lines (28 loc) · 860 Bytes
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
var fs = require("fs")
//read files and then import them for functions
var commandFunctions = new Map()
onStart()
function onStart() {
var files = fs.readdirSync("./commands")
for (var i = 0; i < files.length; i++) {
var file = files[i]
var command = require("./commands/" + file)
commandFunctions.set(file.split(".")[0], command)
}
}
/**
*
* @param {discordTypes.APIApplicationCommandInteraction} interaction
* @returns
*/
async function commands(interaction) {
var commandName = interaction.data.name
var commandArgs = new Map()
if (interaction.data.options) {
for (var i = 0; i < interaction.data.options.length; i++) {
commandArgs.set(interaction.data.options[i].name, interaction.data.options[i].value)
}
}
return await commandFunctions.get(commandName).command(commandArgs, interaction)
}
module.exports = { commands, onStart }