Skip to content

⚡ Quick-start kit for scalable Discord bots, featuring Discord.js v14, Sheweny framework, and Mongoose integration.

License

Notifications You must be signed in to change notification settings

Pexilo/Template-DJS14-Sheweny

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DiscordJS V14 Sheweny Template

image(3)

Version License: MIT

⚡ About The Template

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.

🛠 Installation

Fork the project or click on button.

git clone your-repo
cd your-repo
npm install

🔧 Usage

  1. Add your bot token and mongodb connection string in .env.
  2. Run npm start.

✨ Features

  • 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.

🌎 Integrated languages

• ☕ English᲼᲼᲼᲼᲼᲼᲼• 🥖 French

🧑‍💻 Technical stuff

LanguageManager Technical Details

Structure

📦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 in language-manager.ts.

When a new LanguageManager object is instantiated, it reads all JSON files in src/lang, parsing them into its translations object.

Methods

  • 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.

Usage

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;

MongoDB and Mongoose Integration

Structure

📦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 and user.ts.
  • Database Operations: Methods for interacting with MongoDB are located in shortcuts.ts.

Mongoose Schemas

  • Guild Schema (guild.ts): Defines a guild with id and language fields.
  • User Schema (user.ts): Defines a user with id and guilds fields.

Database Operations (shortcuts.ts)

  • Creating Records: CreateGuild and CreateUser methods are used to create new guild and user records.
  • Deleting Records: DeleteGuild and DeleteUser remove records based on their id.
  • Fetching Records: FetchGuild, FetchUser, and FetchUsersFromGuild retrieve records.
  • Updating Records: UpdateGuild and UpdateUser modify existing records.

These MongoDB schemas and operations are designed to be compatible with multiple guilds and users without any issues.

Usage

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...)

⚠️ Important note, when containing code, make sure to enclose your translated variable within an 'eval' statement.
For examples, see clientMissingPermissions, userMissingPermissions tranlations.

📝 License

MIT License Copyright (c) 2023 Pexilo

👏 Show your support

Simply give me a ⭐️ to support me! 😄

⚙️ Detailed installation steps

Requirements

  • 📃 Node.js 16.9 or higher

MongoDB:

  1. Create an account
  2. Create a cluster
  3. Connect it with "connect your application"
  4. Copy your connection string
  5. Replace <password> with your database access user password
  6. Keep it for later use

Discord bot:

  1. Log in to your Discord account on the Discord Developer Portal website.
  2. Click the "New Application" button to create a new application.
  3. Give your application a name and click "Create."
  4. In the left panel, click on "Bot" in the menu.
  5. Click the "Add Bot" button.
  6. Under the "Token" section, click "Copy" to copy the bot's token. Use "Reset" if you can't copy it right away.
  7. Keep your token and client ID for later use
  8. Under the "Privileged Gateway Intents" section, enable "Servers Members" & "Message Content" intents.

💫 Quick start

git clone https://github.com/YOURNAME/Template-DJS14-Sheweny
🧾 ENV FILE
  1. Replace content of example.env
DISCORD_TOKEN=your-bot-token
MONGO_URI=your-mongo-db-connection-string
  1. Rename the file example.env > .env
🤖 BOT INVITE
  1. Finish the above steps.
  2. Go to the URL Generator option on the Discord Developer Portal.
  3. Check bot and applications.commands options then Administrator permission for developing purposes.
  4. Paste the link in your browser and add the bot to your server

🚀 START BOT

  1. Install dependencies
npm i
  1. Start the bot
npm start

🦾 Powered by


Made with ❤️ by Pexilo

About

⚡ Quick-start kit for scalable Discord bots, featuring Discord.js v14, Sheweny framework, and Mongoose integration.

Topics

Resources

License

Stars

Watchers

Forks