我是编码新手,我自己编写了一个用 Node.js 编码的不和谐机器人,它可以更改整个 config.json、启动机器人、停止机器人、创建实例等......想要更改 config.json 的特定部分而不是整个配置。
{
"cookie": "",
"proxy": "",
"webhook": "https://discord.com/api/webhooks/...",
"sending": [
1647598632,
1647676420
],
"receiving": [
124127383
]
}
我想从一个简单的不和谐命令中更改“发送”(当前为 1647598632、1647676420)和“接收”(当前为 124127383)的内容,例如,
$mass_send 124127383 [1647598632,1647676420].
我想要它,所以我可以更改ID。如果您想交叉引用我为更改整个配置而不是特定变量而编写的代码,请告诉我。感谢任何帮助的人。
我确实有一个 Config updater 命令,但它会更新整个配置而不是配置的特定部分
}
else if (command === '$setconfig') {
if (message.attachments.size < 1)
return message.reply({
embeds: [
new MessageEmbed()
.setColor('RED')
.setDescription('Please attach a new config file.')
]
})
const attachment = message.attachments.first();
console.log(attachment);
if (!attachment.contentType || attachment.contentType.indexOf('text/plain') < 0)
return message.reply({
embeds: [
new MessageEmbed()
.setColor('RED')
.setDescription('Config must be a .txt/.ini file.')
]
})
superagent('GET', attachment.url)
.then(resp => {
const configText = resp.text;
try {
ini.parse(configText);
} catch {
return message.reply({
embeds: [
new MessageEmbed()
.setColor('RED')
.setDescription('Failed to parse ini file.')
]
})
}
fs.writeFileSync(instanceDirectory + '/settings.ini', configText);
return message.reply({
embeds: [
new MessageEmbed()
.setColor('RED')
.setDescription('Config file successfully updated.\nstop the bot with `$stop`')
]
})
})
我想编辑特定部分而不是整个配置。请让我知道这是否可能谢谢!另外,如果不清楚,请告诉我,我可以提供更多信息。