upgrade to discord.js v14
This commit is contained in:
24 files changed
+1598
-1560
No files matched your search
@@ -23,6 +23,22 @@ class Logger {
|
||||
) + colors.yellow(" | Info: " + Text)
|
||||
);
|
||||
}
|
||||
|
||||
error(Text) {
|
||||
let d = new Date();
|
||||
this.logger.log({
|
||||
level: "error",
|
||||
message:
|
||||
`${d.getHours()}:${
|
||||
d.getMinutes
|
||||
} - ${d.getDate()}:${d.getMonth()}:${d.getFullYear()} | Error: ` + Text,
|
||||
});
|
||||
console.log(
|
||||
colors.green(
|
||||
`${d.getDate()}:${d.getMonth()}:${d.getFullYear()} - ${d.getHours()}:${d.getMinutes()}`
|
||||
) + colors.yellow(" | Error: ") + colors.red(Text)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Logger;
|
||||
@@ -1,36 +1,39 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { Routes } = require('discord.js');
|
||||
const { REST } = require('@discordjs/rest');
|
||||
|
||||
/**
|
||||
* Register slash commands for a guild
|
||||
* @param {require("../structures/QuarksBot")} client
|
||||
* @param {string} guild
|
||||
*/
|
||||
module.exports = (client, guild) => {
|
||||
|
||||
let commandsDir = path.join(__dirname, "..", "commands");
|
||||
module.exports = async function(client, guild) {
|
||||
|
||||
fs.readdir(commandsDir, (err, files) => {
|
||||
if (err) throw err;
|
||||
files.forEach(async (file) => {
|
||||
let cmd = require(commandsDir + "/" + file);
|
||||
if (!cmd.SlashCommand || !cmd.SlashCommand.run) return;
|
||||
let dataStuff = {
|
||||
name: cmd.name,
|
||||
description: cmd.description,
|
||||
options: cmd.SlashCommand.options,
|
||||
};
|
||||
const commands = [];
|
||||
const commandFiles = fs.readdirSync(path.join(__dirname, "..", "commands")).filter(file => file.endsWith('.js'));
|
||||
|
||||
//Creating variables like this, So you might understand my code :)
|
||||
let ClientAPI = client.api.applications(client.user.id);
|
||||
let GuildAPI = ClientAPI.guilds(guild);
|
||||
// Place your client and guild ids here
|
||||
const clientId = client.application.id;
|
||||
const guildId = guild;
|
||||
|
||||
try {
|
||||
await GuildAPI.commands.post({ data: dataStuff });
|
||||
} catch (e) {
|
||||
if (client.config.Dev == 'DEV.') console.log(e);
|
||||
client.log('Error: API missing permissions, re-invite the bot');
|
||||
}
|
||||
});
|
||||
});
|
||||
for (const file of commandFiles) {
|
||||
const command = require(`../commands/${file}`);
|
||||
commands.push(command);
|
||||
}
|
||||
|
||||
const rest = new REST({ version: '10' }).setToken(client.config.Token);
|
||||
|
||||
try {
|
||||
client.log('Started refreshing application (/) commands.');
|
||||
|
||||
await rest.put(
|
||||
Routes.applicationGuildCommands(clientId, guildId),
|
||||
{ body: commands },
|
||||
);
|
||||
|
||||
client.log('Successfully reloaded application (/) commands.');
|
||||
} catch (error) {
|
||||
client.error(error);
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user