├── .github └── FUNDING.yml ├── .gitignore ├── LICENSE ├── README.md ├── config.example.js ├── package.json ├── src ├── bot.js ├── commands │ └── ping.js ├── events │ ├── interactionCreate.js │ └── ready.js ├── handlers │ ├── commands.js │ └── events.js └── shard.js └── start.js /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: turkerssh -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | config.js 2 | node_modules 3 | package-lock.json -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Türker 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🍃 Discord.js@^14.16.3 Template 2 | A template for Discord.js@^14.16.3 bots. 3 | 4 | ## 📦 Installation 5 | 1. Clone the repository. 6 | ```sh 7 | $ git clone https://github.com/turkerssh/discord.js-v14-bot-template.git 8 | ``` 9 | 2. Install the dependencies. 10 | ```sh 11 | $ npm install 12 | ``` 13 | 3. Rename the `config.example.js` file to `config.js` and fill in the required fields. 14 | 4. Start the bot. 15 | ```sh 16 | $ npm run start 17 | ``` 18 | 19 | ## 📝 License 20 | This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. 21 | -------------------------------------------------------------------------------- /config.example.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | GeneralInformation: { 3 | BotName: "BOT_NAME", 4 | BotToken: "BOT_TOKEN", 5 | BotId: "BOT_ID", 6 | }, 7 | 8 | PresenceInformation: { 9 | ActivityState: "BOT_ACTIVITY_TEXT", 10 | }, 11 | 12 | WebhookInformation: { 13 | ShardWebhook: "SHARD_WEBHOOK_URL", 14 | }, 15 | }; 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@turkerssh/discord.js-v14-template-bot", 3 | "version": "2.0.0", 4 | "description": "🍃 Advanced discord.js empty bot template", 5 | "main": "start.js", 6 | "scripts": { 7 | "start": "node start.js", 8 | "format": "prettier --write ." 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/turkerssh/discord.js-v14-template-bot" 13 | }, 14 | "dependencies": { 15 | "@turkerssh/logger": "^0.0.2", 16 | "discord.js": "^14.16.3", 17 | "figlet": "^1.8.0", 18 | "fs": "^0.0.1-security" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/bot.js: -------------------------------------------------------------------------------- 1 | const logger = require("@turkerssh/logger"); 2 | const { 3 | Client, 4 | GatewayIntentBits, 5 | Partials, 6 | Collection, 7 | } = require("discord.js"); 8 | 9 | const config = require("../config"); 10 | 11 | const client = new Client({ 12 | intents: [Object.keys(GatewayIntentBits)], 13 | partials: [Object.keys(Partials)], 14 | allowedMentions: { 15 | parse: ["users", "roles"], 16 | repliedUser: true, 17 | }, 18 | }); 19 | 20 | client.interaction = new Collection(); 21 | client.commands = new Collection(); 22 | client.cooldowns = new Collection(); 23 | client.shards = new Collection(); 24 | 25 | ["events", "commands"].filter(Boolean).forEach((h) => { 26 | require(`./handlers/${h}`)(client); 27 | }); 28 | 29 | process.on("unhandledRejection", (err) => { 30 | logger.error({ 31 | type: "client", 32 | message: err, 33 | }); 34 | }); 35 | 36 | process.on("uncaughtException", (err) => { 37 | logger.error({ 38 | type: "client", 39 | message: err, 40 | }); 41 | }); 42 | 43 | process.on("warning", (warning) => { 44 | logger.warn({ 45 | type: "client", 46 | message: warning, 47 | }); 48 | }); 49 | 50 | client.login(config.GeneralInformation.BotToken).catch((err) => { 51 | logger.error({ 52 | type: "client", 53 | message: "Error while logging in", 54 | }); 55 | console.dir(err); 56 | }); 57 | -------------------------------------------------------------------------------- /src/commands/ping.js: -------------------------------------------------------------------------------- 1 | const { SlashCommandBuilder } = require("@discordjs/builders"); 2 | const { EmbedBuilder } = require("discord.js"); 3 | 4 | module.exports = { 5 | data: new SlashCommandBuilder() 6 | .setName("ping") 7 | .setDescription("Check bot ping."), 8 | async execute(interaction) { 9 | const embed = new EmbedBuilder() 10 | .setDescription(`🏓 Pong! **${interaction.client.ws.ping}ms**.`) 11 | .setColor("#13131B"); 12 | await interaction.reply({ embeds: [embed] }); 13 | }, 14 | }; 15 | -------------------------------------------------------------------------------- /src/events/interactionCreate.js: -------------------------------------------------------------------------------- 1 | const logger = require("@turkerssh/logger"); 2 | 3 | module.exports = (client) => { 4 | client.on("interactionCreate", async (interaction) => { 5 | if (!interaction.isCommand()) return; 6 | const command = client.commands.get(interaction.commandName); 7 | if (!command) return; 8 | 9 | try { 10 | logger.debug({ 11 | type: "interaction", 12 | message: `${interaction.user.tag} executed ${interaction.commandName} command`, 13 | }); 14 | await command.execute(interaction); 15 | } catch (error) { 16 | logger.error({ 17 | type: "interaction", 18 | message: error, 19 | }); 20 | await interaction.reply({ 21 | content: "There was an error while executing this command!", 22 | ephemeral: true, 23 | }); 24 | } 25 | }); 26 | }; 27 | -------------------------------------------------------------------------------- /src/events/ready.js: -------------------------------------------------------------------------------- 1 | const { ActivityType, EmbedBuilder } = require("discord.js"); 2 | 3 | const logger = require("@turkerssh/logger"); 4 | const config = require("../../config"); 5 | 6 | module.exports = (client) => { 7 | client.user.setPresence({ 8 | activities: [ 9 | { 10 | name: config.PresenceInformation.ActivityState, 11 | type: ActivityType.Custom, 12 | }, 13 | ], 14 | status: "idle", 15 | }); 16 | 17 | logger.success({ 18 | type: "client", 19 | message: `${client.user.tag} is ready!`, 20 | }); 21 | }; 22 | -------------------------------------------------------------------------------- /src/handlers/commands.js: -------------------------------------------------------------------------------- 1 | const logger = require("@turkerssh/logger"); 2 | const { readdirSync } = require("fs"); 3 | 4 | const config = require("../../config"); 5 | 6 | const { REST } = require("@discordjs/rest"); 7 | const { Routes } = require("discord-api-types/v9"); 8 | 9 | module.exports = (client) => { 10 | const commands = []; 11 | const commandFiles = readdirSync("./src/commands").filter((file) => 12 | file.endsWith(".js"), 13 | ); 14 | for (const file of commandFiles) { 15 | const command = require(`../commands/${file}`); 16 | commands.push(command.data.toJSON()); 17 | client.commands.set(command.data.name, command); 18 | } 19 | const rest = new REST({ version: "9" }).setToken( 20 | config.GeneralInformation.BotToken, 21 | ); 22 | (async () => { 23 | try { 24 | await rest.put( 25 | Routes.applicationCommands(config.GeneralInformation.BotId), 26 | { body: commands }, 27 | ); 28 | 29 | logger.success({ 30 | type: "commands", 31 | message: "Successfully registered application commands", 32 | }); 33 | } catch (error) { 34 | logger.error({ 35 | type: "commands", 36 | message: "Error while registering application commands", 37 | }); 38 | } 39 | })(); 40 | }; 41 | -------------------------------------------------------------------------------- /src/handlers/events.js: -------------------------------------------------------------------------------- 1 | const logger = require("@turkerssh/logger"); 2 | const { readdirSync } = require("fs"); 3 | const allevents = []; 4 | 5 | module.exports = (client) => { 6 | let amount = 0; 7 | for (const file of readdirSync("./src/events").filter((f) => 8 | f.endsWith(".js"), 9 | )) { 10 | try { 11 | const module = require("../events/" + file); 12 | let eventName = file.split(".")[0]; 13 | allevents.push(eventName); 14 | client.on(eventName, module.bind(null, client)); 15 | amount++; 16 | } catch (e) { 17 | logger.error({ 18 | type: "events", 19 | message: `Error while loading event ${file}`, 20 | }); 21 | console.log(e); 22 | } 23 | } 24 | }; 25 | -------------------------------------------------------------------------------- /src/shard.js: -------------------------------------------------------------------------------- 1 | const logger = require("@turkerssh/logger"); 2 | const { ShardingManager, WebhookClient } = require("discord.js"); 3 | 4 | const config = require("../config"); 5 | 6 | const webhook = new WebhookClient({ 7 | url: config.WebhookInformation.ShardWebhook, 8 | }); 9 | 10 | exports.run = async () => { 11 | const manager = new ShardingManager("./src/bot.js", { 12 | token: config.GeneralInformation.BotToken, 13 | totalShards: "auto", 14 | respawn: true, 15 | mode: "process", 16 | }); 17 | 18 | manager.on("shardCreate", (shard) => { 19 | logger.info({ 20 | type: "shard", 21 | message: `Shard ${shard.id} launched`, 22 | }); 23 | 24 | webhook.send( 25 | `🟢 []: Shard **#${shard.id}** online!`, 26 | ); 27 | }); 28 | 29 | manager.spawn().catch((err) => { 30 | logger.error({ 31 | type: "shard", 32 | message: "Error while spawning shards", 33 | }); 34 | console.dir(err); 35 | 36 | webhook.send( 37 | `🔴 []: Error while spawning shards!`, 38 | ); 39 | }); 40 | }; 41 | -------------------------------------------------------------------------------- /start.js: -------------------------------------------------------------------------------- 1 | const logger = require("@turkerssh/logger"); 2 | const figlet = require("figlet"); 3 | 4 | const config = require("./config"); 5 | 6 | figlet(config.GeneralInformation.BotName, (err, data) => { 7 | if (err) { 8 | logger.error({ 9 | type: "figlet", 10 | message: "Something went wrong...", 11 | }); 12 | console.dir(err); 13 | return; 14 | } 15 | console.log(data); 16 | }); 17 | 18 | require("./src/shard.js").run(); 19 | --------------------------------------------------------------------------------