0

I'm programming my first Discord Bot and I already deployed it using Heroku and that's working as expected, for now on my personnal Discord server for my tests.

There is the code, it's very short (sorry if that's not well-coded, I'm beginer at this language). https://github.com/AudricCh/NewWorldServerStatus/blob/main/bot/main.py

But I've got some global variables which are modifiable by using commands, like

$lang EN

Which set some variables with the good translation.

I saw that if I change my code then deploy it, the language is reset because the variable value is lost.

  • What is the good way to save some data, specifically for each Discord server using the Bot ?

  • And are we agree that variables are linked to Discord Servers and are not global for all ones ?! Am I crazy thinking that ?

Thank you !

  • You can use files or a database to store data. Take a look at the [sqlite3](https://docs.python.org/3/library/sqlite3.html) module for a database you can use. You can also take a look at using a JSON file to store key-value pairs. – CryptoNoob Jul 27 '21 at 20:36
  • You're telling me that actually the variables are shared between all Discord servers using the Bot ? If one change the language, others have their changed ? Thanks, I will look at this then, I guess I have to store the unique id of the server with the key-value pairs of my variables – Call Me Audric Jul 27 '21 at 20:41
  • I think using one file for each server would be a good solution, if that is the behaviour you are looking for. If u want something to persist between all servers you could go for a single file and use it globally. – CryptoNoob Jul 27 '21 at 20:45
  • @CryptoNoob Ok thanks a lot, I don't know why I was thinking it will work alone like I've done, make no sense at all. I think files are easiest and free compare to SqlLite. I just need to be sure I have enought space to store them. – Call Me Audric Jul 27 '21 at 20:53
  • Yeah no problem. – CryptoNoob Jul 27 '21 at 21:00
  • @CryptoNoob, SQLite won't work as you expect on Heroku due to its [ephemeral filesystem](https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem). A client-server database must be used instead. – ChrisGPT was on strike Jul 27 '21 at 23:30
  • @Chris So I cannot use files too because of the ephemeral filesystem ? The only solution is to have an external database like mySql ? – Call Me Audric Jul 28 '21 at 08:39
  • That is correct, @CallMeAudric. See [Can I use a file based database on Heroku?](https://stackoverflow.com/a/50421349/354577), for example. – ChrisGPT was on strike Jul 28 '21 at 12:50

0 Answers0