I am experimenting with the Discord API and trying to create some fun bots. As long as it is meant to be present on more than one server, you need to include DB in your script to handle combinations of servers, rooms and users to post and respond to correct channels and correct servers.
Because i do not expect the bot to grow so much, i have chosen the SQLite which would be more than enough for these purposes.
However, in some phase i started to face weir behavior of my bot. I was handling some commands, storing some info about the user evoked that command and iteracting with a database a little bit.
The script worked for me, and worked for some more testers. However some testers were facing really unexpected behavior, getting random data, not saving their progress and so.
I was really confused, as the functions were working for most users, but not all of them.
The informations about users were stored in SQLite based to their discord ID. Which is maximally 18 digits in all cases we tried. The SQLite, according its documentation, supports integer values up to 8bytes (signed/unsigned) so it should be enough. But...
After many attempts to debug the code, I discovered that affected users were getting different IDs for different commands, which was really weird. I thought it was a problem with the Discords API, but after some more research I discovered that SQLite was returning different lines of SQL. For example, the first command used registered an entry with the user's ID. It was the real user id. But then when another command was invoked, the SQLite was asked to return the row that belongs to the user with the given userid. However, for some users, the SQLite for some IDs, returned different entries for each attempt. So the problem was that the DB system was not able to compare large integer values and make this mess. So the solution seemed to be to change the userid column from integer to text. Now it compares the IDs as strings instead of integers, which is slower, but at least it works...
But... who would expect such messy behaviour? I can understand that this kind of comparison mishap can happen with floats, but integers? So weird...
Jan "Jenkings" Škoda - blog
Simplifying IT, Amplifying Knowledge