Setting separate server variables for discord bot using mongodb

Viewed 340

I am wondering how you set variables for separate discord servers so I can use different data in different servers I have set up a MongoDB for storing the data but I have looked through forums and found nothing about setting separate server variables in discord.py

db = cluster["Discord"]
collection = db["Discord"]
population = collection.find()

client = commands.Bot(command_prefix='$')


@client.event
async def on_ready():
    change_status.start()
    print("----------------------")
    print("Logged In As")
    print("Username: %s" % client.user.name)
    print("ID: %s" % client.user.id)
    print("----------------------")
1 Answers

You would probably be best off by inserting a list of dictionaries into your MongoDB. There are lots of good sources on how to do this if you don't know how to. Here's what the dictionary could sort of look like.

[{"id": guildID, "variable": 0}, {"id": guildID, "variable": 1}]

You could search like this.

for guild in guildList:
    if guild["id"] == ctx.guild.id:
        variable = guild["variable"]
Related