Skip to content

Commit

Permalink
✨ | Added Typings & IDE Support
Browse files Browse the repository at this point in the history
  • Loading branch information
NamVr committed Jun 9, 2022
1 parent fbf003a commit ec5e1bd
Show file tree
Hide file tree
Showing 27 changed files with 346 additions and 172 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ This template comes in with many in-built useful and flexible features, such as
- This template comes with a dynamic button interaction handler to receive and process button interactions.
- Buttons can be classified in two category folders.

#### **[NEW] Dynamic Modals Interaction Handler:**

- Easily handle incoming modal submittions using the template handler!
- Modals can be categorized in different folders.

#### **[NEW] Dynamic Context Menu Handler:**

- All new addition to discord API is context menus! You can right click a user or message -> Apps to find these options!
Expand Down
3 changes: 2 additions & 1 deletion bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ const { token, client_id, test_guild_id } = require("./config.json");

/**
* From v13, specifying the intents is compulsory.
* @type {import("discord.js").Client}
* @type {import('./typings').Client}
* @description Main Application Client */

// @ts-ignore
const client = new Client({
// Please add all intents you need, more detailed information @ https://ziad87.net/intents/
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
Expand Down
22 changes: 7 additions & 15 deletions commands/misc/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @file Dynamic help command
* @author Naman Vrati
* @since 1.0.0
* @version 3.2.2
*/

// Deconstructing prefix from config file to use in help command
Expand All @@ -10,28 +11,24 @@ const { prefix } = require("./../../config.json");
// Deconstructing MessageEmbed to create embeds within this command
const { MessageEmbed } = require("discord.js");

/**
* @type {import('../../typings').LegacyCommand}
*/
module.exports = {
name: "help",
description: "List all commands of bot or info about a specific command.",
aliases: ["commands"],
usage: "[command name]",
cooldown: 5,

/**
* @description Executes when the command is called by command handler.
* @author Naman Vrati
* @param {import("discord.js").Message} message The Message Object of the command.
* @param {String[]} args The Message Content of the received message seperated by spaces (' ') in an array, this excludes prefix and command/alias itself.
*/

execute(message, args) {
const { commands } = message.client;

// If there are no args, it means it needs whole help command.

if (!args.length) {
/**
* @type {import("discord.js").MessageEmbed}
* @type {MessageEmbed}
* @description Help command embed object
*/

Expand All @@ -54,7 +51,7 @@ module.exports = {
.send({ embeds: [helpEmbed] })

.then(() => {
if (message.channel.type === "dm") return;
if (message.channel.type === "DM") return;

// On validation, reply back.

Expand Down Expand Up @@ -83,11 +80,6 @@ module.exports = {

const name = args[0].toLowerCase();

/**
* @type {Object}
* @description The command object
*/

const command =
commands.get(name) ||
commands.find((c) => c.aliases && c.aliases.includes(name));
Expand All @@ -99,7 +91,7 @@ module.exports = {
}

/**
* @type {import("discord.js").MessageEmbed}
* @type {MessageEmbed}
* @description Embed of Help command for a specific command.
*/

Expand Down
18 changes: 5 additions & 13 deletions commands/misc/ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,15 @@
* @file Sample ping command
* @author Naman Vrati
* @since 1.0.0
* @version 3.2.2
*/

/**
* @type {import('../../typings').LegacyCommand}
*/
module.exports = {
name: "ping",

/** You need to uncomment below properties if you need them. */
//description: 'Ping!',
//usage: 'put usage here',
//permissions: 'SEND_MESSAGES',
//guildOnly: true,

/**
* @description Executes when the command is called by command handler.
* @author Naman Vrati
* @param {import("discord.js").Message} message The Message Object of the command.
* @param {String[]} args The Message Content of the received message seperated by spaces (' ') in an array, this excludes prefix and command/alias itself.
*/
// Refer to typings.d.ts for available properties.

execute(message, args) {
message.channel.send({ content: "Pong." });
Expand Down
22 changes: 7 additions & 15 deletions commands/misc/reload.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
/**
* @file Command reloader
* @file Live command reloader
* @author Naman Vrati
* @since 1.0.0
* @version 3.2.2
*/

// "fs" declared is used in reloading command cache of the specified command.
const fs = require("fs");

/**
* @type {import('../../typings').LegacyCommand}
*/
module.exports = {
name: "reload",
description: "Reloads a command",
args: true,
ownerOnly: true,

/**
* @description Executes when the command is called by command handler.
* @author Naman Vrati
* @param {import("discord.js").Message} message The Message Object of the command.
* @param {String[]} args The Message Content of the received message seperated by spaces (' ') in an array, this excludes prefix and command/alias itself.
*/

execute(message, args) {
/**
* @type {String}
Expand All @@ -28,11 +25,6 @@ module.exports = {

const commandName = args[0].toLowerCase();

/**
* @type {Object}
* @description The command object itself which is specified.
*/

const command =
message.client.commands.get(commandName) ||
message.client.commands.find(
Expand Down Expand Up @@ -72,8 +64,8 @@ module.exports = {

try {
/**
* @type {Object}
* @description New Command Code Fetch
* @type {import('../../typings').LegacyCommand}
* @description The new command (code fetch)
*/

const newCommand = require(`../${folderName}/${command.name}.js`);
Expand Down
7 changes: 2 additions & 5 deletions events/buttonInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @file Button Interaction Handler
* @author Naman Vrati
* @since 3.0.0
* @version 3.2.2
*/

module.exports = {
Expand All @@ -10,7 +11,7 @@ module.exports = {
/**
* @description Executes when an interaction is created and handle it.
* @author Naman Vrati
* @param {import("discord.js").ButtonInteraction} interaction The interaction which was created
* @param {import('discord.js').ButtonInteraction & { client: import('../typings').Client }} interaction The interaction which was created
*/

async execute(interaction) {
Expand All @@ -20,10 +21,6 @@ module.exports = {
// Checks if the interaction is a button interaction (to prevent weird bugs)

if (!interaction.isButton()) return;
/**
* @description The Interaction command object
* @type {import("discord.js").ButtonInteraction}
*/

const command = client.buttonCommands.get(interaction.customId);

Expand Down
15 changes: 3 additions & 12 deletions events/contextInteraction.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* @file Context Interaction Handler
* @author Krish Garg
* @author Krish Garg & Naman Vrati
* @since 3.0.0
* @version 3.2.2
*/

module.exports = {
Expand All @@ -10,7 +11,7 @@ module.exports = {
/**
* @description Executes when an interaction is created and handle it.
* @author Naman Vrati
* @param {import("discord.js").ContextMenuInteraction} interaction The interaction which was created
* @param {import('discord.js').ContextMenuInteraction & { client: import('../typings').Client }} interaction The interaction which was created
*/

execute: async (interaction) => {
Expand All @@ -26,11 +27,6 @@ module.exports = {
// Checks if the interaction target was a user

if (interaction.targetType === "USER") {
/**
* @description The Interaction command object
* @type {import("discord.js").ContextMenuInteraction}
*/

const command = client.contextCommands.get(
"USER " + interaction.commandName
);
Expand All @@ -51,11 +47,6 @@ module.exports = {
}
// Checks if the interaction target was a user
else if (interaction.targetType === "MESSAGE") {
/**
* @description The Interaction command object
* @type {import("discord.js").ContextMenuInteraction}
*/

const command = client.contextCommands.get(
"MESSAGE " + interaction.commandName
);
Expand Down
13 changes: 5 additions & 8 deletions events/messageCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @file Message Based Commands Handler
* @author Naman Vrati
* @since 1.0.0
* @version 3.2.2
*/

// Declares constants (destructured) to be used in this file.
Expand All @@ -21,7 +22,7 @@ module.exports = {
/**
* @description Executes when a message is created and handle it.
* @author Naman Vrati
* @param {import("discord.js").Message} message The message which was created.
* @param {import('discord.js').Message & { client: import('../typings').Client }} message The message which was created.
*/

async execute(message) {
Expand Down Expand Up @@ -84,11 +85,6 @@ module.exports = {
if (!message.content.startsWith(matchedPrefix) || message.author.bot)
return;

/**
* @description The message command object.
* @type {Object}
*/

const command =
client.commands.get(commandName) ||
client.commands.find(
Expand All @@ -107,15 +103,16 @@ module.exports = {

// Guild Only Property, add in your command properties if true.

if (command.guildOnly && message.channel.type === "dm") {
if (command.guildOnly && message.channel.type === "DM") {
return message.reply({
content: "I can't execute that command inside DMs!",
});
}

// Author perms property
// Will skip the permission check if command channel is a DM. Use guildOnly for possible error prone commands!

if (command.permissions) {
if (command.permissions && message.channel.type !== "DM") {
const authorPerms = message.channel.permissionsFor(message.author);
if (!authorPerms || !authorPerms.has(command.permissions)) {
return message.reply({ content: "You can not do this!" });
Expand Down
7 changes: 2 additions & 5 deletions events/modalInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @file Modal Interaction Handler
* @author Naman Vrati
* @since 3.2.0
* @version 3.2.2
*/

module.exports = {
Expand All @@ -10,7 +11,7 @@ module.exports = {
/**
* @description Executes when an interaction is created and handle it.
* @author Naman Vrati
* @param {import("discord.js").Interaction} interaction The interaction which was created
* @param {import('discord.js').Interaction & { client: import('../typings').Client }} interaction The interaction which was created
*/

async execute(interaction) {
Expand All @@ -20,10 +21,6 @@ module.exports = {
// Checks if the interaction is a modal interaction (to prevent weird bugs)

if (!interaction.isModalSubmit()) return;
/**
* @description The Interaction command object
* @type {import("discord.js").ModalSubmitInteraction}
*/

const command = client.modalCommands.get(interaction.customId);

Expand Down
5 changes: 3 additions & 2 deletions events/onReady.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
* @file Ready Event File.
* @author Naman Vrati
* @since 1.0.0
* @version 3.2.2
*/

module.exports = {
name: "ready",
once: true,

/**
* @description Executes the block of code when client is ready (bot initialization)
* @param {import("discord.js").Client} client Main Application Client
* @description Executes when client is ready (bot initialization).
* @param {import('../typings').Client} client Main Application Client.
*/
execute(client) {
console.log(`Ready! Logged in as ${client.user.tag}`);
Expand Down
7 changes: 2 additions & 5 deletions events/selectInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @file Select Menu Interaction Handler
* @author Naman Vrati
* @since 3.0.0
* @version 3.2.2
*/

module.exports = {
Expand All @@ -10,7 +11,7 @@ module.exports = {
/**
* @description Executes when an interaction is created and handle it.
* @author Naman Vrati
* @param {import("discord.js").SelectMenuInteraction} interaction The interaction which was created
* @param {import('discord.js').SelectMenuInteraction & { client: import('../typings').Client }} interaction The interaction which was created
*/

async execute(interaction) {
Expand All @@ -20,10 +21,6 @@ module.exports = {
// Checks if the interaction is a select menu interaction (to prevent weird bugs)

if (!interaction.isSelectMenu()) return;
/**
* @description The Interaction command object
* @type {import("discord.js").SelectMenuInteraction}
*/

const command = client.selectCommands.get(interaction.customId);

Expand Down
7 changes: 2 additions & 5 deletions events/slashCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @file Slash Command Interaction Handler
* @author Naman Vrati
* @since 3.0.0
* @version 3.2.2
*/

module.exports = {
Expand All @@ -10,7 +11,7 @@ module.exports = {
/**
* @description Executes when an interaction is created and handle it.
* @author Naman Vrati
* @param {import("discord.js").CommandInteraction} interaction The interaction which was created
* @param {import('discord.js').CommandInteraction & { client: import('../typings').Client }} interaction The interaction which was created
*/

async execute(interaction) {
Expand All @@ -20,10 +21,6 @@ module.exports = {
// Checks if the interaction is a command (to prevent weird bugs)

if (!interaction.isCommand()) return;
/**
* @description The Interaction command object
* @type {import("discord.js").CommandInteraction}
*/

const command = client.slashCommands.get(interaction.commandName);

Expand Down
Loading

0 comments on commit ec5e1bd

Please sign in to comment.