Compare commits
5 commits
011002e379
...
ef7976cada
Author | SHA1 | Date | |
---|---|---|---|
ef7976cada | |||
e14a713431 | |||
ff23a7a616 | |||
7597dbc05c | |||
1dd3baf0c3 |
8 changed files with 104 additions and 6 deletions
|
@ -8,8 +8,8 @@
|
||||||
"ecmaVersion": 2021
|
"ecmaVersion": 2021
|
||||||
},
|
},
|
||||||
"rules": {
|
"rules": {
|
||||||
|
"no-unused-vars": "warn",
|
||||||
"arrow-spacing": ["warn", { "before": true, "after": true }],
|
"arrow-spacing": ["warn", { "before": true, "after": true }],
|
||||||
"brace-style": ["error", "stroustrup", { "allowSingleLine": true }],
|
|
||||||
"comma-dangle": ["error", "always-multiline"],
|
"comma-dangle": ["error", "always-multiline"],
|
||||||
"comma-spacing": "error",
|
"comma-spacing": "error",
|
||||||
"comma-style": "error",
|
"comma-style": "error",
|
||||||
|
@ -25,10 +25,10 @@
|
||||||
"no-floating-decimal": "error",
|
"no-floating-decimal": "error",
|
||||||
"no-inline-comments": "error",
|
"no-inline-comments": "error",
|
||||||
"no-lonely-if": "error",
|
"no-lonely-if": "error",
|
||||||
"no-multi-spaces": "error",
|
"no-multi-spaces": "warn",
|
||||||
"no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1, "maxBOF": 0 }],
|
"no-multiple-empty-lines": ["warn", { "max": 2, "maxEOF": 1, "maxBOF": 0 }],
|
||||||
"no-shadow": ["error", { "allow": ["err", "resolve", "reject"] }],
|
"no-shadow": ["error", { "allow": ["err", "resolve", "reject"] }],
|
||||||
"no-trailing-spaces": ["error"],
|
"no-trailing-spaces": ["warn"],
|
||||||
"no-var": "error",
|
"no-var": "error",
|
||||||
"object-curly-spacing": ["error", "always"],
|
"object-curly-spacing": ["error", "always"],
|
||||||
"prefer-const": "error",
|
"prefer-const": "error",
|
||||||
|
|
5
config.example.json
Normal file
5
config.example.json
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"token": "Token",
|
||||||
|
"clientId": "Client ID",
|
||||||
|
"guildId": "Guild ID"
|
||||||
|
}
|
|
@ -1 +0,0 @@
|
||||||
TOKEN="Example"
|
|
46
deploy.js
Normal file
46
deploy.js
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
const { REST, Routes } = require('discord.js');
|
||||||
|
const { clientId, guildId, token } = require('./config.json');
|
||||||
|
const fs = require('node:fs');
|
||||||
|
const path = require('node:path');
|
||||||
|
|
||||||
|
const commands = [];
|
||||||
|
// Grab all the command files from the commands directory you created earlier
|
||||||
|
const foldersPath = path.join(__dirname, 'commands');
|
||||||
|
const commandFolders = fs.readdirSync(foldersPath);
|
||||||
|
|
||||||
|
for (const folder of commandFolders) {
|
||||||
|
// Grab all the command files from the commands directory you created earlier
|
||||||
|
const commandsPath = path.join(foldersPath, folder);
|
||||||
|
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
|
||||||
|
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
|
||||||
|
for (const file of commandFiles) {
|
||||||
|
const filePath = path.join(commandsPath, file);
|
||||||
|
const command = require(filePath);
|
||||||
|
if ('data' in command && 'execute' in command) {
|
||||||
|
commands.push(command.data.toJSON());
|
||||||
|
} else {
|
||||||
|
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct and prepare an instance of the REST module
|
||||||
|
const rest = new REST().setToken(token);
|
||||||
|
|
||||||
|
// and deploy your commands!
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
console.log(`Started refreshing ${commands.length} application (/) commands.`);
|
||||||
|
|
||||||
|
// The put method is used to fully refresh all commands in the guild with the current set
|
||||||
|
const data = await rest.put(
|
||||||
|
Routes.applicationGuildCommands(clientId, guildId),
|
||||||
|
{ body: commands },
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
|
||||||
|
} catch (error) {
|
||||||
|
// And of course, make sure you catch and log any errors!
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
})();
|
50
index.js
50
index.js
|
@ -1,15 +1,63 @@
|
||||||
// Require the necessary discord.js classes
|
// Require the necessary discord.js classes
|
||||||
const { Client, Events, GatewayIntentBits } = require('discord.js');
|
const fs = require('node:fs');
|
||||||
|
const path = require('node:path');
|
||||||
|
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
|
||||||
const { token } = require('./config.json');
|
const { token } = require('./config.json');
|
||||||
|
|
||||||
// Create a new client instance
|
// Create a new client instance
|
||||||
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||||
|
|
||||||
|
// Handle dynamically reading and executing commands.
|
||||||
|
client.commands = new Collection();
|
||||||
|
|
||||||
|
// Retrieve the commands directory and the files inside of it, including subdirectories.
|
||||||
|
const foldersPath = path.join(__dirname, 'commands');
|
||||||
|
const commandDirectories = fs.readdirSync(foldersPath);
|
||||||
|
|
||||||
|
// Load the command files.
|
||||||
|
for (const directory of commandDirectories) {
|
||||||
|
const commandsPath = path.join(foldersPath, directory);
|
||||||
|
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
|
||||||
|
for (const file of commandFiles) {
|
||||||
|
const filePath = path.join(commandsPath, file);
|
||||||
|
const command = require(filePath);
|
||||||
|
// Set a new item in the Collection with the key as the command's name and the value as the exported module.
|
||||||
|
if ('data' in command && 'execute' in command) {
|
||||||
|
client.commands.set(command.data.name, command);
|
||||||
|
} else {
|
||||||
|
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// When the client is ready, run this code (only once)
|
// When the client is ready, run this code (only once)
|
||||||
// We use 'c' for the event parameter to keep it separate from the already defined 'client'
|
// We use 'c' for the event parameter to keep it separate from the already defined 'client'
|
||||||
client.once(Events.ClientReady, c => {
|
client.once(Events.ClientReady, c => {
|
||||||
console.log(`Ready! Logged in as ${c.user.tag}`);
|
console.log(`Ready! Logged in as ${c.user.tag}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Create a listener to respond to interaction events.
|
||||||
|
client.on(Events.InteractionCreate, async interaction => {
|
||||||
|
if (!interaction.isChatInputCommand()) return;
|
||||||
|
|
||||||
|
const command = interaction.client.commands.get(interaction.commandName);
|
||||||
|
|
||||||
|
if (!command) {
|
||||||
|
console.error(`No command matching ${interaction.commandName} was found.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await command.execute(interaction);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
if (interaction.replied || interaction.deffered) {
|
||||||
|
await interaction.followUp({ content: 'There was an error while executing this command!', epheremal: true });
|
||||||
|
} else {
|
||||||
|
await interaction.reply({ content: 'There was an error while executing this command!', epheremal: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Log in to Discord with your client's token
|
// Log in to Discord with your client's token
|
||||||
client.login(token);
|
client.login(token);
|
||||||
|
|
Loading…
Reference in a new issue