I'm currently working on a public discord bot, and I wanted to make the server decide their settings, how am I able to make per server settings, I understand I need a database like sqlite3 or MySQL, but what would the code be?
I'm currently working on a public discord bot, and I wanted to make the server decide their settings, how am I able to make per server settings, I understand I need a database like sqlite3 or MySQL, but what would the code be?
Let's say you have the prefix of your bot set up like this on index.js and that your bot's name is @Ma Boop Boi#1234:
let prefix = "!";
but a bot's user already calls another bot called @Butler#6789 on their server (Server B) by also using "!". @Ma Boop Boi needs to fetch the let prefix variable from a JSON file that would be thrown by some database so you can have different prefix values. On the discord.js library, servers are known as guild.
object-file-1.json
{
"guild-id": "123456789012345678",
"prefix": "!"
}
object-file-2.json
{
"guild-id": "987654321098765432",
"prefix": "-"
}
I'd highly doubt that you'd want to use config files for each discord server, mostly because they take up so much space and they have a chance to be corrupted over frequent changes to the .json, so what you want to do is use enmaps. https://gist.github.com/eslachance/5c539ccebde9fa76340fb5d54889aa22
If you're wanting to ask further questions about this here's the enmap Discord: https://discord.gg/bRFyWp3