├── .gitignore ├── LICENSE ├── README.md ├── command └── lang │ ├── setlang.js │ └── test.js ├── event ├── messageCreate.js └── ready.js ├── exemple.env ├── index.js ├── language ├── en.js └── fr.js ├── package.json └── utils ├── CustomError.js ├── color.js ├── handlers ├── command.js ├── error.js └── event.js └── logger.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .env 3 | package-lock.json 4 | json.sqlite -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Melio 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 |

Multi-Language-Discord-Bot

2 |

3 | Multi-language Discord Bot (v14) example (fr/en) with command & event handler, by Melio. 4 |
5 | If you like the project, feel free to put a ⭐ for better referencing ; If you need help, join the support server. 6 |

7 | 8 |

9 | MIT License 10 | 11 | Version discord.js 12 | 13 | 14 | Stars 15 | 16 | 17 | Support server 18 | 19 | 20 |
21 |

22 | 23 | ## About 24 | This program is an example of internationalization integration for a Discord Bot. 25 | It's a very simplified example of how to implement several languages in one application. 26 | 27 | Again with a focus on simple code, data is stored with SQLite, via the [quick.db](https://www.npmjs.com/package/quick.db) package. 28 | Of course, you're free to implement any other DBMS (database management system). 29 | 30 | ## Starting the project 31 | 32 | ### Configuration 33 | The configuration file named **.env** have to be created and replace **exemple.env** and content the token of your discord bot, his prefix and your id or the ids of all other owners. 34 | ``` 35 | # Bot configuration 36 | 37 | PREFIX=BOT_PREFIX 38 | TOKEN=BOT_TOKEN 39 | OWNER=YOUR_DISCORD_ID 40 | ``` 41 | 42 | ### Installation 43 | ```sh 44 | $ npm install 45 | ``` 46 | 47 | ### Start the bot 48 | ```sh 49 | $ node index.js 50 | ``` 51 | 52 |
53 | 54 | ## More 55 | 56 | For any errors found, please contact me [here](https://discord.com/invite/G6WQsMQShZ) or do a pull request. 57 | This repository is licensed under the MIT License. See the `LICENSE` file ([here](LICENSE)) for more information. 58 | 59 | ###### This repository was made with ❤️ from my [Structure-Discord-Bot](https://github.com/antoinemcx/Structure-Discord-Bot/tree/master) template repository. 60 | -------------------------------------------------------------------------------- /command/lang/setlang.js: -------------------------------------------------------------------------------- 1 | const { QuickDB } = require("quick.db"); 2 | 3 | module.exports = { 4 | conf: { 5 | name: "setlang", 6 | description: "setlang", 7 | usage: "setlang ", 8 | aliases: ["sl", "lang"], 9 | cooldown: 2, // (Time in second) 10 | dir: "lang", 11 | }, 12 | run: async (bot, message, args) => { 13 | const db = new QuickDB(); 14 | await db.init(); 15 | 16 | let messageToSend; 17 | 18 | if(!args[0]) { 19 | messageToSend = bot.language.SETLANG_ERR; 20 | } else if(args[0] === "en") { 21 | await db.set(`lang_${message.guild.id}`, { lang: "en" }) 22 | messageToSend = bot.language.SETLANG_SUCCESS[1]; 23 | } else if(args[0] === "fr") { 24 | await db.set(`lang_${message.guild.id}`, { lang: "fr" }); 25 | messageToSend = bot.language.SETLANG_SUCCESS[0]; 26 | } else { 27 | messageToSend = bot.language.SETLANG_ERR; 28 | } 29 | 30 | message.channel.send(messageToSend); 31 | } 32 | } -------------------------------------------------------------------------------- /command/lang/test.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | conf: { 3 | name: "test", 4 | description: "test", 5 | usage: "test", 6 | aliases: ["t"], 7 | dir: "lang", 8 | }, 9 | run: async (bot, message, args) => { 10 | message.channel.send(bot.language.TEST_MESSAGE) 11 | } 12 | } -------------------------------------------------------------------------------- /event/messageCreate.js: -------------------------------------------------------------------------------- 1 | const { Collection } = require("discord.js"); 2 | require('dotenv').config() 3 | const prefix = process.env.PREFIX; 4 | const { QuickDB } = require("quick.db"); 5 | const db = new QuickDB(); 6 | 7 | module.exports = async (bot, message) => { 8 | if (message.author.bot) { return } 9 | 10 | //LANGUAGE 11 | await db.init(); 12 | 13 | default_lang = "en" 14 | lang_query = await db.get(`lang_${message.guild.id}`); 15 | bot.language = require(`../language/${lang_query === null ? default_lang : lang_query.lang}.js`); 16 | 17 | if(message.content.match(new RegExp(`^<@!?${bot.user.id}>( |)$`))) { // bot mentionned in the message 18 | message.channel.send(bot.language.MENTION_BOT.replace(//g, bot.user.username) 19 | .replace(//g, prefix)); 20 | 21 | } else if (message.content.startsWith(prefix)) { // bot prefix used 22 | const command = message.content.split(' ')[0].slice(prefix.length).toLowerCase(); 23 | const args = message.content.split(' ').slice(1); 24 | let cmd; 25 | 26 | if (bot.commandes.has(command)) { 27 | cmd = bot.commandes.get(command); 28 | } else if (bot.aliases.has(command)) { 29 | cmd = bot.commandes.get(bot.aliases.get(command)); 30 | } 31 | if(!cmd) return; 32 | 33 | const props = require(`../command/${cmd.conf.dir}/${cmd.conf.name}`); 34 | 35 | // COOLDOWNS 36 | if (!cooldowns.has(props.conf.name)) { 37 | cooldowns.set(props.conf.name, new Collection()); // cooldown creation 38 | } 39 | 40 | const now = Date.now(); 41 | const timestamps = cooldowns.get(props.conf.name); 42 | const cooldownAmount = (props.conf.cooldown || 1) * 1000; 43 | 44 | if (timestamps.has(message.author.id)) { 45 | let expirationTime = timestamps.get(message.author.id) + cooldownAmount; 46 | 47 | if (now < expirationTime) { 48 | const timeLeft = (expirationTime - now) / 1000; 49 | return message.channel.send(bot.language.COOLDOWN_ERR.replace(/