Best Way to store data for an Discord Bot
Hey everyone,
i need some input from some experts 😉
I am trying to build an Discord Bot who gives Roles to user when they put an Emote under an specific text. I know there are probably many bots that do exactly that but i want to practice my skills.
So the first things already working but now i am at the point to store data and i am not sure whats the best way for it.
Yes i could wrote it into my SQL Server but i think its way to overkill.
So i thought about XML/Json files but i am not sure how good they are in that case. The bot will not have that much "traffic", since it will only be "private", but still at every emote it needs to check the Data in the files which can be edited every time.
What would you do in that case?
Thanks in advance
4 Replies
On what I read now you want to store the message ID of the corresponding message under which emojis should be placed on.
Therefore you could make a json file to replicate a structure like this:
MessageId = id : ulong
Emojis = List
Emoji1 = emojiId = ulong
Emoji2 = emojiId = ulong
Emoji3 = emojiId = ulong
blubb.......
Then you can create a model for this json in your bot and read the data at the boot time of the bot to store it in inside and check after every emoji added event from discord if the specific emoji you want to push out a role is added to the specific message you entered.
At least that's the way I'd do it
okay thanks for the input, can you easily add some new Emojis in the Json?
and do you know if you edit the message does it gets an new id?
ahh okay its not so easy to add emojis if its an "hard" model when i am correct 😉
One message should only have one single ID but you're able to check this easily by enabling the developer mode in Discord, copy the original id of the message, edit it and then copy the new ID of the message. Compare them and you should get the same ID.
Regarding the emoji adding, you can also let the bot make IO ops every time a new emoji is added to a message to check if it's inside the list.
My suggestion is that I just restart the bot because I have to access the server anyway so I can do it the same time
okay thanks - edited
yeah the ids are the same 😉