-
Notifications
You must be signed in to change notification settings - Fork 108
/
index.js
72 lines (62 loc) · 1.93 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
const Discord = require("discord.js")
const dotenv = require("dotenv")
const { REST } = require("@discordjs/rest")
const { Routes } = require("discord-api-types/v9")
const fs = require("fs")
const { Player } = require("discord-player")
dotenv.config()
const TOKEN = process.env.TOKEN
const LOAD_SLASH = process.argv[2] == "load"
const CLIENT_ID = "924846888929337354"
const GUILD_ID = "924832445050781766"
const client = new Discord.Client({
intents: [
"GUILDS",
"GUILD_VOICE_STATES"
]
})
client.slashcommands = new Discord.Collection()
client.player = new Player(client, {
ytdlOptions: {
quality: "highestaudio",
highWaterMark: 1 << 25
}
})
let commands = []
const slashFiles = fs.readdirSync("./slash").filter(file => file.endsWith(".js"))
for (const file of slashFiles){
const slashcmd = require(`./slash/${file}`)
client.slashcommands.set(slashcmd.data.name, slashcmd)
if (LOAD_SLASH) commands.push(slashcmd.data.toJSON())
}
if (LOAD_SLASH) {
const rest = new REST({ version: "9" }).setToken(TOKEN)
console.log("Deploying slash commands")
rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), {body: commands})
.then(() => {
console.log("Successfully loaded")
process.exit(0)
})
.catch((err) => {
if (err){
console.log(err)
process.exit(1)
}
})
}
else {
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}`)
})
client.on("interactionCreate", (interaction) => {
async function handleCommand() {
if (!interaction.isCommand()) return
const slashcmd = client.slashcommands.get(interaction.commandName)
if (!slashcmd) interaction.reply("Not a valid slash command")
await interaction.deferReply()
await slashcmd.run({ client, interaction })
}
handleCommand()
})
client.login(TOKEN)
}