Answer the question
In order to leave comments, you need to log in
How to make it so that the JSON file is updated on the host (I use the Heroku host) - discord.py rewrite?
I am using a library and JSON file to change prefixes on different servers.
That is, if my bot enters some server, then the ID of this server and the default prefix are entered in the JSON file. and when the prefix is changed on the server, then the prefix in the JSON file should change to the one specified by the user on the server.
If you run the bot locally, then everything is OK, everything works, but if you upload it all to GitHub and then to the host, then when the user then there are no changes in the file.
Here is the code for changing the prefix:
def get_prefix(bot, message):
with open('prefixserv.json','r') as f:
prefixserv= json.load(f)
return prefixserv[str(message.guild.id)]
bot=commands.Bot(command_prefix=get_prefix)
@bot.event
async def on_guild_join(guild):
with open('prefixserv.json','r') as f:
prefixserv= json.load(f)
prefixserv[str(guild.id)]= '.'
with open('prefixserv.json','w') as f:
json.dump(prefixserv, f, indent=4)
@bot.event
async def on_giuld_remove(guild):
with open('prefixserv.json','r') as f:
prefixserv= json.load(f)
prefixserv.pop(str(guild.id))
with open('prefixserv.json','w') as f:
json.dump(prefixserv, f, indent=4)
@bot.command(aliases=['change_prefix','new_prefix','nprefix'])
async def prefix(ctx,prefix):
with open('prefixserv.json', 'r') as f:
prefixserv = json.load(f)
prefixserv[str(ctx.guild.id)] = prefix
with open('prefixserv.json', 'w') as f:
json.dump(prefixserv, f, indent=4)
await ctx.send(f'Префикс был изменен на {prefix}')
{
"732623824293724221": "/",
"615807835162411029": "."
}
Answer the question
In order to leave comments, you need to log in
What didn't you like about the database?
1) speed
2) compactness
3) ease of use
4) data is not stored in files
5) data integrity,
etc.
if you plan to promote the bot in the future, then json simply cannot cope with a large amount of information - I advise you all- rethink your decision.
if it's your problem, first make sure heroku has automatic file updates enabled:
I'm not entirely sure that the file can be updated at all
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question