{ discord.js v12 } Per-Server Settings/Config

Viewed 2925

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?

2 Answers

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": "-"
}
Related