Merge branch 'master' of git.codingvm.codes:snxraven/DiscordJS-v13-Template
This commit is contained in:
commit
1af66c7c00
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
node_modules
|
||||||
|
.env
|
||||||
|
package-lock.json
|
@ -2,6 +2,7 @@ const { EmbedBuilder } = require('discord.js');
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "ping",
|
name: "ping",
|
||||||
|
private: true,
|
||||||
description: "Returns websocket latency",
|
description: "Returns websocket latency",
|
||||||
|
|
||||||
run: async (client, interaction) => {
|
run: async (client, interaction) => {
|
||||||
|
16
commands/context/ping.js
Normal file
16
commands/context/ping.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
const { EmbedBuilder } = require('discord.js');
|
||||||
|
const {ApplicationCommandType } = require('discord.js');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: "ping-test",
|
||||||
|
type: ApplicationCommandType.Message,
|
||||||
|
run: async (client, interaction) => {
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor("#FF0000")
|
||||||
|
.setTitle("🏓 Pong!")
|
||||||
|
.setDescription(`Latency : ${client.ws.ping}ms`)
|
||||||
|
.setTimestamp()
|
||||||
|
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
|
||||||
|
interaction.followUp({ embeds: [embed] });
|
||||||
|
},
|
||||||
|
};
|
@ -1,13 +1,72 @@
|
|||||||
const client = require("../index");
|
const client = require("../index");
|
||||||
|
require("dotenv").config();
|
||||||
|
const { glob } = require("glob");
|
||||||
|
const { promisify } = require("util");
|
||||||
|
const globPromise = promisify(glob);
|
||||||
|
|
||||||
client.on("interactionCreate", async (interaction) => {
|
client.on("interactionCreate", async (interaction) => {
|
||||||
|
|
||||||
|
// Slash Commands
|
||||||
|
const slashCommands = await globPromise(`${process.cwd()}/commands/*/*.js`);
|
||||||
|
const arrayOfSlashCommands = [];
|
||||||
|
|
||||||
|
// Map the slash commands into data to be processed
|
||||||
|
slashCommands.map((value) => {
|
||||||
|
const file = require(value);
|
||||||
|
const splitted = value.split("/");
|
||||||
|
const directory = splitted[splitted.length - 2];
|
||||||
|
|
||||||
|
if (!file?.name) return;
|
||||||
|
|
||||||
|
const properties = {
|
||||||
|
directory,
|
||||||
|
...file
|
||||||
|
};
|
||||||
|
client.slashCommands.set(file.name, properties);
|
||||||
|
|
||||||
|
if (["MESSAGE", "USER"].includes(file.type)) delete file.description;
|
||||||
|
|
||||||
|
// Push the data
|
||||||
|
arrayOfSlashCommands.push(file);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// Slash Command Handling
|
// Slash Command Handling
|
||||||
if (interaction.isChatInputCommand()) {
|
if (interaction.isChatInputCommand()) {
|
||||||
await interaction.deferReply({ ephemeral: false }).catch(() => { });
|
|
||||||
|
// Grabbing Command Data for this interaction
|
||||||
|
let commandData = []
|
||||||
|
|
||||||
|
// We use ForEach here to filter our array into the single commands info.
|
||||||
|
await arrayOfSlashCommands.forEach(command => {
|
||||||
|
if (command.name == interaction.commandName) {
|
||||||
|
commandData.push(command)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Process and Parse Data
|
||||||
|
let dataToProcess = JSON.stringify(commandData[0])
|
||||||
|
let parsedData = JSON.parse(dataToProcess)
|
||||||
|
|
||||||
|
// If the command is private, set ephemeral true else, set false
|
||||||
|
console.log(parsedData)
|
||||||
|
if (parsedData.private == true) {
|
||||||
|
await interaction.deferReply({
|
||||||
|
ephemeral: true
|
||||||
|
}).catch(() => {});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
await interaction.deferReply({
|
||||||
|
ephemeral: false
|
||||||
|
}).catch(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const cmd = client.slashCommands.get(interaction.commandName);
|
const cmd = client.slashCommands.get(interaction.commandName);
|
||||||
if (!cmd)
|
if (!cmd)
|
||||||
return interaction.followUp({ content: "An error has occurred " });
|
return interaction.followUp({
|
||||||
|
content: "An error has occurred "
|
||||||
|
});
|
||||||
|
|
||||||
const args = [];
|
const args = [];
|
||||||
|
|
||||||
@ -26,7 +85,9 @@ client.on("interactionCreate", async (interaction) => {
|
|||||||
|
|
||||||
// Context Menu Handling
|
// Context Menu Handling
|
||||||
if (interaction.isContextMenuCommand()) {
|
if (interaction.isContextMenuCommand()) {
|
||||||
await interaction.deferReply({ ephemeral: false });
|
await interaction.deferReply({
|
||||||
|
ephemeral: false
|
||||||
|
});
|
||||||
const command = client.slashCommands.get(interaction.commandName);
|
const command = client.slashCommands.get(interaction.commandName);
|
||||||
if (command) command.run(client, interaction);
|
if (command) command.run(client, interaction);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user