J'ai une question à propos de Python et Json. Je suis en train de coder un bot pour discord en utilisant discord py et je voulais avoir un fichier de configuration. Dans mon code, j'ai besoin de remplacer une chaîne d'une variable située dans un fichier Python.Remplacer la chaîne par Python dans Json
Ceci est mon code actuel:
#change prefix
@bot.command(pass_context=True)
async def prefix(ctx, newprefix):
with open("config.json", 'a+') as f:
stringified = JSON.stringify(json)
stringified.replace('"prefix" : prefix, "prefix" : newprefix')
await ctx.send("Prefix set to: `{}`. New prefix will be applied after restart.".format(newprefix))
author = ctx.message.author
print(author, "has changed the prefix to: {}".format(newprefix))
et:
{
"nowplaying":"with buttons",
"ownerid":"173442411878416384",
"prefix":"?",
"token":"..."
}
Quand j'entrez la commande: ?prefix *newprefix*
, il n'y a pas de sortie dans la discorde ou le terminal, rien ne change. Quelqu'un peut-il me montrer un moyen de faire cela?
Voulez-vous remplacer 'préfixe' par 'newprefix'? – zaidfazil