Initial commit
This commit is contained in:
47
.eslintrc.json
Normal file
47
.eslintrc.json
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"extends": "eslint:recommended",
|
||||
"env": {
|
||||
"node": true,
|
||||
"es6": true
|
||||
},
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2021
|
||||
},
|
||||
"rules": {
|
||||
"brace-style": ["error", "stroustrup", { "allowSingleLine": true }],
|
||||
"comma-dangle": ["error", "always-multiline"],
|
||||
"comma-spacing": "error",
|
||||
"comma-style": "error",
|
||||
"curly": ["error", "multi-line", "consistent"],
|
||||
"dot-location": ["error", "property"],
|
||||
"handle-callback-err": "off",
|
||||
"indent": ["error", "tab"],
|
||||
"max-nested-callbacks": ["error", { "max": 4 }],
|
||||
"max-statements-per-line": ["error", { "max": 2 }],
|
||||
"no-console": "off",
|
||||
"no-empty-function": "error",
|
||||
"no-floating-decimal": "error",
|
||||
"no-inline-comments": "error",
|
||||
"no-lonely-if": "error",
|
||||
"no-multi-spaces": "error",
|
||||
"no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1, "maxBOF": 0 }],
|
||||
"no-shadow": ["error", { "allow": ["err", "resolve", "reject"] }],
|
||||
"no-trailing-spaces": ["error"],
|
||||
"no-var": "error",
|
||||
"object-curly-spacing": ["error", "always"],
|
||||
"prefer-const": "error",
|
||||
"quotes": ["error", "single"],
|
||||
"semi": ["error", "always"],
|
||||
"space-before-blocks": "error",
|
||||
"space-before-function-paren": ["error", {
|
||||
"anonymous": "never",
|
||||
"named": "never",
|
||||
"asyncArrow": "always"
|
||||
}],
|
||||
"space-in-parens": "error",
|
||||
"space-infix-ops": "error",
|
||||
"space-unary-ops": "error",
|
||||
"spaced-comment": "error",
|
||||
"yoda": "error"
|
||||
}
|
||||
}
|
||||
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
config.json
|
||||
.vscode
|
||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 Gustavo
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
46
commands/dev/ping.js
Normal file
46
commands/dev/ping.js
Normal file
@@ -0,0 +1,46 @@
|
||||
const {
|
||||
MessageActionRow,
|
||||
MessageButton,
|
||||
} = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: 'ping',
|
||||
description: 'Replies with Pong!',
|
||||
options: [{
|
||||
name: 'input',
|
||||
type: 'STRING',
|
||||
description: 'input arg',
|
||||
required: true,
|
||||
}],
|
||||
permissions: [{
|
||||
id: '870383205306494997',
|
||||
type: 'ROLE',
|
||||
permission: false,
|
||||
},
|
||||
{
|
||||
id: '873349611358670878',
|
||||
type: 'ROLE',
|
||||
permission: false,
|
||||
},
|
||||
],
|
||||
async execute(interaction) {
|
||||
const {
|
||||
value: input,
|
||||
} = interaction.options.get('input');
|
||||
|
||||
const row = new MessageActionRow()
|
||||
.addComponents(
|
||||
new MessageButton()
|
||||
.setCustomId('button')
|
||||
.setLabel('Button')
|
||||
.setStyle('PRIMARY'),
|
||||
);
|
||||
|
||||
interaction.reply({
|
||||
content: `Ping ${input}`,
|
||||
components: [row],
|
||||
});
|
||||
|
||||
// console.log(`Ping! ${interaction.options.get('input').value}`);
|
||||
},
|
||||
};
|
||||
68
commands/dev/reload.js
Normal file
68
commands/dev/reload.js
Normal file
@@ -0,0 +1,68 @@
|
||||
const fs = require('fs');
|
||||
|
||||
const {
|
||||
owner,
|
||||
} = require('../../index');
|
||||
|
||||
module.exports = {
|
||||
name: 'reload',
|
||||
description: 'Reloads a command or all commands, for development purposes.',
|
||||
defaultPermissions: false,
|
||||
options: [{
|
||||
name: 'command',
|
||||
type: 'STRING',
|
||||
description: 'Name of the command to reload.',
|
||||
required: true,
|
||||
}],
|
||||
permissions: [{
|
||||
id: owner.id,
|
||||
type: 'USER',
|
||||
permission: true,
|
||||
}],
|
||||
async execute(interaction) {
|
||||
const {
|
||||
clientCommands,
|
||||
commands,
|
||||
} = require('../../index');
|
||||
|
||||
const commandName = interaction.options.getString('command');
|
||||
|
||||
if (!(await commands.fetch()).find(command => command.name === commandName)) {
|
||||
return interaction.reply({
|
||||
content: `No such command \`${commandName}\` found.`,
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
else if (commandName === 'reload') {
|
||||
return interaction.reply({
|
||||
content: 'You can\'t reload this command.',
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
const commandFolders = fs.readdirSync('./commands');
|
||||
const folderName = commandFolders.find(folder => fs.readdirSync(`./commands/${folder}`).includes(`${commandName}.js`));
|
||||
|
||||
delete require.cache[require.resolve(`../${folderName}/${commandName}.js`)];
|
||||
|
||||
try {
|
||||
const cmd = require(`../${folderName}/${commandName}.js`);
|
||||
clientCommands.set(commandName, {
|
||||
id: (await commands.fetch()).find(command => command.name === commandName).id,
|
||||
data: cmd,
|
||||
});
|
||||
await interaction.reply({
|
||||
content: `Command \`${commandName}\` reload completed.`,
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
await interaction.reply({
|
||||
content: `A error occur while trying to reload \`${interaction.commandName}\`\n\`\`\`${error}\`\`\``,
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
},
|
||||
};
|
||||
110
index.js
Normal file
110
index.js
Normal file
@@ -0,0 +1,110 @@
|
||||
const Discord = require('discord.js');
|
||||
const fs = require('fs');
|
||||
|
||||
const {
|
||||
token,
|
||||
guildId,
|
||||
} = require('./config.json');
|
||||
|
||||
const client = new Discord.Client({
|
||||
intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_MESSAGE_REACTIONS'],
|
||||
});
|
||||
const clientCommands = new Discord.Collection();
|
||||
|
||||
async function registryCommands() {
|
||||
|
||||
const owner = (await client.application.fetch()).owner;
|
||||
|
||||
module.exports = {
|
||||
owner,
|
||||
};
|
||||
|
||||
console.time('Duration');
|
||||
|
||||
const guildCommands = client.guilds.cache.get(guildId).commands;
|
||||
|
||||
const commandsData = [];
|
||||
|
||||
const commandFolders = fs.readdirSync('./commands');
|
||||
|
||||
for (const folder of commandFolders) {
|
||||
|
||||
const commandFiles = fs.readdirSync(`./commands/${folder}`).filter(file => file.endsWith('.js'));
|
||||
|
||||
for (const file of commandFiles) {
|
||||
|
||||
const cmd = require(`./commands/${folder}/${file}`);
|
||||
|
||||
clientCommands.set(cmd.name, cmd);
|
||||
|
||||
commandsData.push(cmd);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
await guildCommands.set(commandsData);
|
||||
|
||||
for (const folder of commandFolders) {
|
||||
|
||||
const commandFiles = fs.readdirSync(`./commands/${folder}`).filter(file => file.endsWith('.js'));
|
||||
|
||||
for (const file of commandFiles) {
|
||||
|
||||
const cmd = require(`./commands/${folder}/${file}`);
|
||||
|
||||
const cmdId = (await guildCommands.fetch()).find(command => command.name === cmd.name).id;
|
||||
|
||||
clientCommands.set(cmd.name, {
|
||||
id: cmdId,
|
||||
data: cmd,
|
||||
});
|
||||
|
||||
(await guildCommands.fetch(cmdId)).permissions.set({
|
||||
id: cmdId,
|
||||
permissions: cmd.permissions,
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
clientCommands,
|
||||
guildCommands,
|
||||
};
|
||||
|
||||
console.group('\nCOMMANDS REGISTERED');
|
||||
|
||||
console.timeEnd('Duration');
|
||||
console.log('Commands table:');
|
||||
console.table(clientCommands);
|
||||
|
||||
console.groupEnd();
|
||||
|
||||
}
|
||||
|
||||
client.on('ready', async () => {
|
||||
|
||||
registryCommands();
|
||||
|
||||
console.log('-- BOT READY --');
|
||||
|
||||
});
|
||||
|
||||
client.login(token);
|
||||
|
||||
client.on('interactionCreate', async interaction => {
|
||||
|
||||
if (!interaction.isCommand() || !clientCommands.has(interaction.commandName)) return;
|
||||
|
||||
try {
|
||||
await clientCommands.get(interaction.commandName).data.execute(interaction);
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
await interaction.reply({
|
||||
content: `A error occur while trying to execute \`${interaction.commandName}\`\n\`\`\`${error}\`\`\``,
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
2605
package-lock.json
generated
Normal file
2605
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
19
package.json
Normal file
19
package.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "templated.js",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "node .",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "Lored",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"discord.js": "^13.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^7.31.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user