-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.js
More file actions
93 lines (82 loc) · 2.75 KB
/
main.js
File metadata and controls
93 lines (82 loc) · 2.75 KB
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
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")
const { FFmpeg } = require("discord-player/dist")
const { YoutubeiExtractor } = require("discord-player-youtubei")
process.on("uncaughtException", (exception) => {
//i know, it's stupid. but it stops crashes
console.log(exception.name)
console.log(exception.stack)
console.log(exception.message)
})
dotenv.config()
const TOKEN = process.env.TOKEN;
const CLIENT_ID = process.env.CLIENT_ID;
const GUILD_ID = process.env.GUILD_ID;
const LOAD_SLASH = process.argv[2] == "load"
const client = new Discord.Client({
intents: [
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildVoiceStates
]
})
const player = Player.singleton(client, {
Options: {
quality: "highestaudio",
highWaterMark: 1 << 25
}
})
player.extractors.loadDefault();
player.extractors.register(YoutubeiExtractor, {});
client.slashcommands = new Discord.Collection();
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())
}
//not sure if I like LOAD_SLASH, I might turn this into a separate file to be ran individually later
if (LOAD_SLASH) {
const rest = new REST({ version: "10" }).setToken(TOKEN)
console.log("Deploying slash commands")
rest.put(Routes.applicationCommands(CLIENT_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.execute(client, interaction);
}
if (interaction.isAutocomplete()){
const command = client.slashcommands.get(interaction.commandName);
try{
command.autocomplete(client, interaction);
}
catch(err){
console.log(err);
}
}
handleCommand()
})
client.login(TOKEN)
}