This is more than just a template. The DiscordJS V14 Sheweny Template aims to provide a strong foundation for Discord bot development. Built with Discord.js v14 and the Sheweny framework, it offers a scalable and feature-rich starting point for both beginners and experienced djs developers. The purpose of this model is to save initial steps time.
Fork the project or click on button.
git clone your-repo
cd your-repo
npm install
- Add your bot token and mongodb connection string in
.env
. - Run
npm start
.
- Command handling
- Event handling
- Scalable architecture
- Pre-configured
- Languages support
Don't want languages system ?
Use no-multi-languages branch.
Or no-multi-languages-js for javascript language.
📦src
┣ 📂commands
┃ ┗ 📜language.command.ts
┣ 📂lang
┃ ┣ 📜en.json
┃ ┗ 📜fr.json
┣ 📂models
┃ ┗ 📜Translations.ts
┣ 📂utils
┗ ┗ 📜language-manager.ts
- Translations Interface: An interface
Translations
is defined to type the translations. - Reading JSON Files: Language JSON files from
src/lang
are read and parsed during the object's construction. - Translation Retrieval: Methods like
getTranslation
,getCommandTranslation
, and others retrieve specific translations based on language and key. Located inlanguage-manager.ts
.
When a new LanguageManager
object is instantiated, it reads all JSON files in src/lang
, parsing them into its translations
object.
getTranslation(key: string, lang: string)
: Retrieves a general translation.getCommandTranslation(lang: string)
: Retrieves command-specific translations.getInterractionTranslation(lang: string)
: Retrieves interaction-specific translations.getEventTranslation(lang: string)
: Retrieves event-specific translations.getUtilsTranslation(lang: string)
: Retrieves utility-specific translations.getAllTranslations(lang: string)
: Retrieves all translations for a specific language.
Suppose you need to get a translation for the ping command in French. You would do something like:
const langManager = new LanguageManager();
const pingCommand = langManager.getCommandTranslation("fr").pingCommand;
📦src
┣ 📂db
┃ ┣ 📜guild.ts
┃ ┣ 📜index.ts
┃ ┗ 📜user.ts
┣ 📂utils
┗ ┗ 📜shortcuts.ts
- Database Models: Stored under the
src/db
directory. There are two main models:guild.ts
anduser.ts
. - Database Operations: Methods for interacting with MongoDB are located in
shortcuts.ts
.
- Guild Schema (
guild.ts
): Defines a guild withid
andlanguage
fields. - User Schema (
user.ts
): Defines a user withid
andguilds
fields.
- Creating Records:
CreateGuild
andCreateUser
methods are used to create new guild and user records. - Deleting Records:
DeleteGuild
andDeleteUser
remove records based on theirid
. - Fetching Records:
FetchGuild
,FetchUser
, andFetchUsersFromGuild
retrieve records. - Updating Records:
UpdateGuild
andUpdateUser
modify existing records.
These MongoDB schemas and operations are designed to be compatible with multiple guilds and users without any issues.
Updating the above example of the language manager to use MongoDB would look like this:
const { guild } = interaction;
const { guildData, lang } = await FetchAndGetLang(guild!);
const langManager = new LanguageManager();
const pingCommand = langManager.getCommandTranslation(lang).pingCommand;
Notice the use of FetchAndGetLang
to retrieve the guild's language and the replacement of getCommandTranslation("fr")
with getCommandTranslation(lang)
.
To create a new translation you have to add it in the en.json
and fr.json
files in the src/lang
folder. Then you have to add the key of the translation it in the Translations
interface in the src/models/Translations.ts
file. Use the key to retrieve the translation in your code.
Don't forget to use the corresponding method to retrieve the translation (for commands use getCommandTranslation
, for events use getEventTranslation
, etc...)
For examples, see clientMissingPermissions
, userMissingPermissions
tranlations.
MIT License Copyright (c) 2023 Pexilo
Simply give me a ⭐️ to support me! 😄
- 📃 Node.js 16.9 or higher
- Create an account
- Create a cluster
- Connect it with "connect your application"
- Copy your connection string
- Replace
<password>
with your database access user password - Keep it for later use
- Log in to your Discord account on the Discord Developer Portal website.
- Click the "New Application" button to create a new application.
- Give your application a name and click "Create."
- In the left panel, click on "Bot" in the menu.
- Click the "Add Bot" button.
- Under the "Token" section, click "Copy" to copy the bot's token. Use "Reset" if you can't copy it right away.
- Keep your token and client ID for later use
- Under the "Privileged Gateway Intents" section, enable "Servers Members" & "Message Content" intents.
- Fork the repo.
git clone https://github.com/YOURNAME/Template-DJS14-Sheweny
- Replace content of
example.env
DISCORD_TOKEN=your-bot-token
MONGO_URI=your-mongo-db-connection-string
- Rename the file
example.env
>.env
- Finish the above steps.
- Go to the URL Generator option on the Discord Developer Portal.
- Check
bot
andapplications.commands
options thenAdministrator
permission for developing purposes. - Paste the link in your browser and add the bot to your server
- Install dependencies
npm i
- Start the bot
npm start
Made with ❤️ by Pexilo