When I run my bot and I run a particular command, when I restart the bot it doesn’t save the json for some reason.
My code:
const commando = require(‘discord.js-commando’);
const Discord = require(“discord.js”);
const oneLine = require(‘common-tags’).oneLine;
const shopitems = require(’/app/shopitems.json’);
const coins = require(’/app/accountbalance.json’);
const inven = require(’/app/userinventory.json’);
const prize = require(’/app/items.json’);
const fs = require(‘fs’);
var removeitem = ‘Mystery Weapon Crate’;
var data = fs.readFileSync(’/app/userinventory.json’);
var json = JSON.parse(data);
function inventor() {
let item = ‘Mystery Weapon Crate’;
return item = ‘Mystery Weapon Crate’
}
module.exports = class ShopCommand extends commando.Command {
constructor(client) {
super(client, {
name: ‘open’,
aliases: [‘open’],
group: ‘economy’,
ownerOnly: true,
memberName: ‘open’,
description: ‘Open a crate you have in your inventory.’,
details: oneLine Open a crate you have in your inventory.
,
examples: [’+open’],
});
}
async run(msg){
if(msg.author.bot) return;
if(!inven[msg.author.id]) {
return msg.channel.send(‘Sorry, you don’t have an inventory(try buying some crates).’);
} else {
let crat = inven[msg.author.id].items.find(inventor);
if(!crat) {
return msg.channel.send(‘Sorry, you don’t have any crates in your inventory at the moment.’);
}
/* let id = msg.member.id;
var itemss = json.id;
var inv = {‘guild’: msg.guild.id, ‘items’:[‘Mystery Weapon Crate’]};
delete inv[‘items’];
*/
let pixe = prize[‘items’][Math.floor(Math.random() * prize[‘items’].length)];
let currit = inven[msg.author.id].items
inven[msg.author.id] = {
guild: msg.guild.id,
items: [currit, pixe.name]
};
fs.writeFile("/app/userinventory.json", JSON.stringify(json), function (err) {
if (err) throw err;
console.log(“Saved!!”)
});