
Recently, I made the decision to move Klee's codebase (around 4,000 lines of code in TypeScript) to a programming language created by JetBrains, Kotlin.
Was it a decision I regret? Definitely not. Klee now uses fewer resources, has improved security, and features a much more organized codebase that was rebuilt from scratch based on mistakes from the past. Klee was built using JDA for Discord, HikariCP for connection pooling, Exposed for SQL, and Caffeine for caching.
After writing thousands of lines of code in Kotlin, I realized that this language is incredibly good! It's similar to TypeScript in some aspects, but quite different in others. I implemented a repository system for every database table (Economy, Pix, Counting, Server Configuration, Bot Ban, etc.). These repositories could only be called through a Kotlin Coroutine (in Klee's case: CoroutineScope(SupervisorJob() + Dispatchers.IO)). Here are some tips I learned throughout this journey:
● Always document your code, whether with JSDocs or KDocs. It will be important not only for other people, but also for yourself in the future.
● Follow a consistent pattern for command structures, classes, repositories, and more. It makes creating and maintaining these things much easier!
● You shouldn't always make your project open-source if you don't expect anyone to contribute to it. There have been cases like Loritta, where people used Loritta's source code to directly compete with it under different branding.
● Create hooks that will be used throughout the entire project before you start writing commands, handlers, and other features. I recently added the ability to change the prefix of my Discord bot, Klee through a command, and many commands were still using a prefix defined in a .env file. Because of that, I had to go through all the commands and replace the old getBotPrefix calls, which well, was a lot of work...
● Plan your bot beforehand: the tools you'll use, the language you'll build it in, which Discord wrapper you'll use, the database, commands, and so on. This will help you a lot in the future.
● Organize your code using folders and categories, for example:
● ◦ commands/blackjack
● ◦ commands/economy
● ◦ commands/moderation
● ◦ commands/rpg
● Create commands for admins to use, such as setting a user's balance (if applicable), banning someone from using the bot, configuring a server's counting system, and so on. And by admin, I mean bot administrators, not server administrators.
● Create Terms of Service and a Privacy Policy for your bot so you can get it verified. Also, you must be at least 16 years old, or have your parents, friends, or someone else assist you with the verification process.
● Create a support server for your bot and promote it on platforms like Top.gg and Disboard.
● Disable intents that you won't use and always prepare your code for when the bot grows, without making it overly complicated. In other words, prepare systems for sharding, clustering, and similar concepts. If you don't know, shards are groups of servers that your bot is connected to (1 shard = 2,500 servers). Once you reach that limit, Discord requires you to implement sharding. Clusters are groups of shards, but they're not necessary unless you want to use them.
And those are my tips. You'll keep learning as you continue developing, and remember to never give up on your project. It's also worth mentioning that just because another bot added a very specific feature doesn't mean you need to add it too. Always think about whether that feature fits your bot, whether it's aligned with its purpose, and whether it matches your goals.