This repository has been archived by the owner on Jun 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
slashhandler.js
55 lines (48 loc) · 1.95 KB
/
slashhandler.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
const fs = require('fs')
const path = require('path')
const { Client } = require('discord.js')
/**
*
* @param {Client} client
*/
module.exports = async function (client) {
var commands = new Array()
function readCommands(dir) {
const files = fs.readdirSync(path.join(__dirname, dir))
for(const file of files) {
const stat = fs.lstatSync(path.join(__dirname, dir, file))
if(stat.isDirectory()) readCommands(path.join(dir, file))
else if(file.endsWith('.js') && !file.startsWith('xx')) {
var command = require(path.join(__dirname, dir, file))
command.path = path.join(__dirname, dir, file)
if(typeof command.permissions === 'string') command.permissions = [command.permissions]
if(command.name) {
console.log(`[${client.user.username}]: ${command.name} wird geladen...`)
commands.push(command)
client.slashCommands.set(command.name, command)
}
}
}
}
readCommands('./slashcommands')
console.log(`[${client.user.username}]: Commands werden hochgeladen.`)
await client.guilds.fetch()
for(var guild of client.guilds.cache) {
guild[1].commands.set(commands)
}
console.log(`[${client.user.username}]: Commands aktiv.`)
client.on('interactionCreate', async function(ita) {
if(ita.isCommand()) {
let command = client.slashCommands.get(ita.commandName)
if(!command) return
var args = {}
ita.options._hoistedOptions.forEach(object => {
args[object.name] = { value: object.value, type: object.type }
})
await command.run(ita, args, client).catch(error => {
console.error(error)
try { require('./embeds').error(ita, 'Fehler', 'Ein unbekannter Fehler ist aufgetreten.') } catch {}
})
}
})
}