0

I have an idea for a Discord bot where each server(guild) can store their own settings in the bot. I don't have much experience with a "real" database such as MySQL or SQLite, and that seems like overkill. Assuming that my bot will be in many servers, what is a resource-efficient way to store settings? I would only be storing a few booleans and strings at most.

  • You could look at MongoDB, they have a free cloud atlas option (500MB). You could also use a JSON file which is quick and easy but not very scalable. – Joshua Nixon Aug 08 '21 at 20:22
  • if your only storing such little amount I would suggest JSON but for anything larger I don't think you can pass on SQL – yotam rec Aug 08 '21 at 21:56

2 Answers2

0

If DB is overkill to you, you can make the path by something like this.

@bot.event
async def on_guild_join(guild):
    path = "serverSetting/" + str(guild.id)
        try:
        os.makedirs(path)
        print("Making dir:" + path)
    # if the dir exist
    except FileExistsError:
        print("Dir exist " + path)

You can write your json file in commands by

path = "serverSetting/" + str(context.guild.id) + "/" + "Setting.json"

Kouheng
  • 383
  • 4
  • 11
-1

It is a bit messy however, you could also store the settings of the server in a text channel. You could then save the settings in a format as JSON. A couple of things need to be considered for this approach:

  1. Discords Terms of service
  2. keeping track of the text channel (could be stored in a local textfile as guid)
  3. making sure that the text channel can not be eddited by users other than the bot. (could be fixed with roles)
  4. reading the data from the text channel (could be acieved by using a json or YAML format)

discord developer policy discord TOS just reading a bit of it you should be able to do this. jou just have to watch out for the rate limit i.e dont read and write to fast.

parse data with json stack overflow parse data with YAML stack overflow parsing YAML and json could be done with these stack overflow posts.