【发布时间】:2017-06-25 12:18:39
【问题描述】:
我有一个关于 Python 和 Json 的问题。 我正在使用 discord py 编写一个不和谐的机器人,我想要一个配置文件。在我的代码中,我需要从位于 Python 文件中的变量中替换一个字符串。
这是我当前的代码:
#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))
和:
{
"nowplaying":"with buttons",
"ownerid":"173442411878416384",
"prefix":"?",
"token":"..."
}
当我输入命令:?prefix *newprefix* 时,discord 或终端没有输出,没有任何变化。谁能告诉我一个方法来做到这一点?
【问题讨论】:
-
你想用'newprefix'替换'prefix'吗?