commit 2966e4c61890bb2d9f00e111a73e36222d92d1cc Author: Raven Scott Date: Fri Jul 22 17:09:13 2022 -0500 first commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..afcaac8 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# Discord-Linx Discord.JS v14 Base Template + +Structure: + +**commands** - This folder contains commands + +**event** - This folder contains files related to discord.js events. (Like "ready", "interactionCreate") + +**handler** - This folder contains files read files from the command folder. + +**index.js** - This is the main file to run the bot. + + + +1) Use ```npm i ``` + +2) Create a .env file ``` touch .env``` + +3) Edit .env +``` +TOKEN = token +``` + +4) Go to Handler -- > index.js and change "GUIDIDHERE" to your Discord Servers Guild ID + +5) Run the bot ```node index.js``` + + +Want to make this better? Issue a pull request! diff --git a/commands/Info/ping.js b/commands/Info/ping.js new file mode 100644 index 0000000..b6dc834 --- /dev/null +++ b/commands/Info/ping.js @@ -0,0 +1,16 @@ +const { Embed } = require("discord.js"); + +module.exports = { + name: "ping", + description: "Returns websocket latency", + + run: async (client, interaction) => { + const embed = new Embed() + .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] }); + }, +}; diff --git a/events/interactionCreate.js b/events/interactionCreate.js new file mode 100644 index 0000000..27e56bf --- /dev/null +++ b/events/interactionCreate.js @@ -0,0 +1,33 @@ +const client = require("../index"); + +client.on("interactionCreate", async (interaction) => { + // Slash Command Handling + if (interaction.isChatInputCommand()) { + await interaction.deferReply({ ephemeral: false }).catch(() => { }); + + const cmd = client.slashCommands.get(interaction.commandName); + if (!cmd) + return interaction.followUp({ content: "An error has occurred " }); + + const args = []; + + for (let option of interaction.options.data) { + if (option.type === "SUB_COMMAND") { + if (option.name) args.push(option.name); + option.options?.forEach((x) => { + if (x.value) args.push(x.value); + }); + } else if (option.value) args.push(option.value); + } + interaction.member = interaction.guild.members.cache.get(interaction.user.id); + + cmd.run(client, interaction, args); + } + + // Context Menu Handling + if (interaction.isContextMenuCommand()) { + await interaction.deferReply({ ephemeral: false }); + const command = client.slashCommands.get(interaction.commandName); + if (command) command.run(client, interaction); + } +}); diff --git a/events/ready.js b/events/ready.js new file mode 100644 index 0000000..e45e333 --- /dev/null +++ b/events/ready.js @@ -0,0 +1,5 @@ +const client = require("../index"); + +client.on("ready", () => { + console.log(`${client.user.tag} is up and ready to go!`); +}); diff --git a/handler/index.js b/handler/index.js new file mode 100644 index 0000000..f763673 --- /dev/null +++ b/handler/index.js @@ -0,0 +1,37 @@ +require("dotenv").config(); +const { glob } = require("glob"); +const { promisify } = require("util"); +const globPromise = promisify(glob); + +module.exports = async (client) => { + // Slash Commands + const slashCommands = await globPromise(`${process.cwd()}/commands/*/*.js`); + const arrayOfSlashCommands = []; + 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; + arrayOfSlashCommands.push(file); + }); + + // Events + const eventFiles = await globPromise(`${process.cwd()}/events/*.js`); + eventFiles.map((value) => require(value)); + + // Slash Commands Register + client.on("ready", async () => { + // Register for a single guild + await client.guilds.cache.get("GUIDIDHERE").commands.set(arrayOfSlashCommands); + + // Register for all the guilds the bot is in + // await client.application.commands.set(arrayOfSlashCommands); + }); + +}; diff --git a/index.js b/index.js new file mode 100644 index 0000000..866b49c --- /dev/null +++ b/index.js @@ -0,0 +1,14 @@ +require("dotenv").config(); +const { Client, Collection } = require("discord.js"); + +const client = new Client({ intents: 32767 }); +module.exports = client; + +// Global Variables +client.commands = new Collection(); +client.slashCommands = new Collection(); + +// Initializing the project +require("./handler")(client); + +client.login(process.env.TOKEN); diff --git a/package.json b/package.json new file mode 100644 index 0000000..1f1e990 --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "dlinuxtemplatev14", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "discord.js": "^14.0.3", + "dotenv": "^16.0.0", + "glob": "^7.2.0" + } +}