Thank you for using my bot template!
This template was developed to make creating new bots quick and easy. To aid in this i have built in multiple systems to make customizing the bot as easy as possible.
-
Built in SQL database support. (SQLite, mySQL, PostgreSQL)
-
Built in translation support, found in
src/util/translations
. -
Easy to use templates for various bot features. (Commands, Features, Modules, Events)
-
Highly customizable config.
-
Commands follow a simple and easy to modify template which is structured as follows:
module.exports = { data: new SlashCommandBuilder() .setName('test') // This is the name which will show on discord .setNameLocalizations(commandTranslaitons("test")) // Loads the names of this command for different languages .setDescription('Testing command'), // Command description // This is a typical slash command builder, check https://discord.js.org/docs/packages/builders/main/SlashCommandBuilder:Class for more information async execute(interaction, client) { // Interaction is a discord.js command interaction, check docs for more info // Client is the bots client, i will provide more information farther down this file interaction.reply({content: `test command`}) }, };
-
Features are addons for the bot, typically single .js files which add simple functionality to the bot, they also have a simple template they follow to make developing them a breeze
module.exports = (client) => { }
As you can tell these are just exporting a function which takes in the client as a parameter, while minimal this is intentional as features are typically intended to extend the client or execute functions already on the client.
-
Modules add complex functionality to the bot and follow a template simular to that of commands, the below code should be placed within a
main.js
file inside the modules subdirectory located in themodules
foldermodule.exports = { name: "test", // This is the module name, this will be shown in the info command async execute(client) { // Module logic } }
The purpose of seperating each module into its own subfolder is for ease of installation and development. Each module should be primarily self contained with its own
.md
file explaining setup. -
While this one is a given for any bot to easily change things such as the bot token ive structured this template to be centered around the config so that as many aspects as possible can be edited by the client either through editing the config.yml file or by using the settings command through discord.
For modules however there is some extra functionality, the client provides a configHandler which can be accessed as such:
client.configHandler
. This handler provides multiple functions for fetching and editing config data allowing modules to add their own config options to the bots base config file.client.configHandler.get(key) // Retreives the config entry for the provided key. client.configHandler.getAll() // Returns the entire config, .get() should be used instead. client.configHandler.edit(key, value) // Edits the config value for the provided key and saves it to file. client.configHandler.load() // Loads the config.yml file into memory, only used on bot load as edit will update the config saved in memory. client.configHandler.save() // Saves the current config stored in memory to file.
-
Translations are built into the bot by default, no need for a extra module.
Translation keys follow a simple to follow naming scheme,
"commandName_textType" (example "Info_Description1")
for text and just the command name for command name localisation. you can get translations by using the following functions.client.translationHandler.getTranslation("Info_Description1", user) // This will get the translation from a specified key getCommandNameTranslations("info") // This will fetch the alternate command name translations for this command getCommandDescriptionTranslations("info") // This will fetch the alternate command description translations for this command
getTranslations()
Will fetch the specified translated string using the users prefered languagegetCommandNameTranslations()
Will fetch the localized versions of the specified command's name from "command_names.yml".getCommandDescriptionTranslations()
Will fetch the localized versions of the specified command's description from "command_descriptions.yml"getCommandOptionTranslations()
Will fetch the localized versions of the specified option from "command_options.yml"Note: logs will default to english
You an also use the
injectTranslations()
function to add in new translations into the translation files from outside sources, mainly modules (this will be done one time upon the first startup of the bot and only again upon updating translations) -
To make handling the different events the
discord.js
client spllies easier ive built in a event handler, events follow a simular structure to modules with a few differences, that being name will be a discord.js event, aswell as the addition of aonce
parameter which will determine if the event will run only the first time the event is fired or every time.const { Events } = require('discord.js'); module.exports = { name: Events.ClientReady, once: true, execute(client) { }, };
-
This template includes a database solution out of the box, it ships with a SQLite database but this can be changed to connect to a remote database by changing a few lines in the
.env
fileDATABASE_DIALECT=sqlite # supports sqlite, postgresql, mysql # Below options are not used with SQLite DATABASE_NAME= # The database name the bot will be using DATABASE_USERNAME= # Username the bot will use when authenticating DATABASE_PASSWORD= # The password the bot will use when authenticating DATABASE_HOST= # The host ip/uri of the database
You can use the functions provided with Sequelize by using the following:
client.sql.models.{model}.{function}
youd replace the bracket parts with your model name and function. the database instance can easily be accessed anywhere that the client is provided. So any modules, functions, commands, etc all will have access.