first commit
This commit is contained in:
commit
2966e4c618
29
README.md
Normal file
29
README.md
Normal file
@ -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!
|
16
commands/Info/ping.js
Normal file
16
commands/Info/ping.js
Normal file
@ -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] });
|
||||
},
|
||||
};
|
33
events/interactionCreate.js
Normal file
33
events/interactionCreate.js
Normal file
@ -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);
|
||||
}
|
||||
});
|
5
events/ready.js
Normal file
5
events/ready.js
Normal file
@ -0,0 +1,5 @@
|
||||
const client = require("../index");
|
||||
|
||||
client.on("ready", () => {
|
||||
console.log(`${client.user.tag} is up and ready to go!`);
|
||||
});
|
37
handler/index.js
Normal file
37
handler/index.js
Normal file
@ -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);
|
||||
});
|
||||
|
||||
};
|
14
index.js
Normal file
14
index.js
Normal file
@ -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);
|
17
package.json
Normal file
17
package.json
Normal file
@ -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"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user