I'm new to coding and I'm currently working on creating a Discord.js bot from scratch with no coding experience. It's a learning process for me as I go along.
Our current project involves developing a bot that can respond with a Discord embed message. The bot is designed for a online game guild where various characters exist, each with unique stats, skills, and types.
The goal is to populate a JSON file with details of all units, so when users use the .unitname
command, the bot will generate an embed containing all relevant information about that unit.
It should resemble this:
https://i.sstatic.net/aeH9b.png
In order to streamline the functionality, creating numerous commands for each individual unit doesn't seem efficient. Therefore, I am considering having the bot scan every message for potential unit requests instead.
While this method may seem inefficient, I am wondering if it will affect the bot's performance in practice?
How can I program the bot to identify inputs like .OneOfDozensFoPossibleUnits
?
Perhaps maintaining a separate list with all unit names and triggering them with .AnyOfThose
would be a more optimal approach, but I am uncertain.
For instance, if the bot identifies .Lucius
as a unit request, it needs to extract the input message, remove the "."
prefix (I hope this is achievable, as "." + "input"
seems cumbersome).
Next, it must search the JSON file for Lucius' data specifically among many other units. How do I accomplish this?
After acquiring data such as stats, they need to fill designated placeholders (as indicated in the code), but what is the syntax for this?
Additionally, I want to include conditional checks using if
statements (e.g., if unit type == "defense", change color to blue). I believe I can find the syntax for this, but your guidance would be greatly appreciated.
Apologies for the somewhat lazy approach by asking for assistance, but due to the collaborative nature of this project, I am exploring unfamiliar territory. Please share any tips or point out any flaws you might discover. Thank you in advance!
client.on('message', message => {
if (message.content === '.' + "unit") {
const embed = new Discord.RichEmbed()
.setAuthor("Author", "https://lh3.googleusercontent.com/rA0lKRGI_-bP-Jj4nkVc5lm6WJfO3nYlAz089otvQnLeevIoao1CTvaU0l0dqnnWIvLZTSOTaEwj6W04IZSRHQz3NYWiePtJnW3bANh54aI=w120")
.setColor(0xFF0000)
.addField("<:stats:545991150486421514> Stats", "⧫ ATK: " + "variable" + "\r\n ⧫ HP: " + "variable" + "\r\n ⧫ DEF: " + "variable", true)
.addField("\u200B", "⧫ CRIT RATE: " + "variable" + "\r\n ⧫ CRIT DMG: " + "variable" + "\r\n ⧫ AGI: " + "variable", true)
.addField("<:skills:545991578355761152> Skills", "Skill descriptions")
.setImage("https://lh3.googleusercontent.com/rA0lKRGI_-bP-Jj4nkVc5lm6WJfO3nYlAz089otvQnLeevIoao1CTvaU0l0dqnnWIvLZTSOTaEwj6W04IZSRHQz3NYWiePtJnW3bANh54aI=w120", 2, 2)
.setThumbnail("https://lh3.googleusercontent.com/rA0lKRGI_-bP-Jj4nkVc5lm6WJfO3nYlAz089otvQnLeevIoao1CTvaU0l0dqnnWIvLZTSOTaEwj6W04IZSRHQz3NYWiePtJnW3bANh54aI=w120")
.setFooter("Footer", "https://lh3.googleusercontent.com/rA0lKRGI_-bP-Jj4nkVc5lm6WJfO3nYlAz089otvQnLeevIoao1CTvaU0l0dqnnWIvLZTSOTaEwj6W04IZSRHQz3NYWiePtJnW3bANh54aI=w120");
message.channel.send(embed);
}
});