javascript discord bot errors


Hi i am currentely hosting a discord bot with discord.js. I try to save user data with a .json file. Somehow i get a lot of errors. (i am hosting it on heroku).
I am not a native english speaker and have no clue about warnings like this. What does it mean? how do i know which line is affected?


    throw new ERR_INVALID_ARG_TYPE(propName, ['string', 'Buffer', 'URL'], path);

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received an instance of Object
    at Object.openSync (node:fs:583:10)
    at Object.readFileSync (node:fs:459:35)
    at Object.<anonymous> (C:\Users\User\Documents\GitHub\Squidbot1\index.js:9:20)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Module._load (node:internal/modules/cjs/loader:827:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47 {

Node.js v18.3.0

bot code:

const express = require("express");
const app = express();

const discord = require("discord.js");
const client = new discord.Client({intents:["GUILDS","GUILD_MESSAGES"]});

const fs = require("fs");
var data = require("./userdata.json");    
var read_data = fs.readFileSync(data);
var datafile = JSON.parse(read_data);

var bump_timeout = true;

var port = process.env.PORT || 3000;

app.listen(port, "", function() {
console.log("Listening on Port 3000");

client.on("message", message => {
  var msg_value = message.content.toLowerCase();
  var username =;
  var id =;
  if(msg_value.includes('hello') && msg_value.includes('bot') || msg_value.includes('hi') && msg_value.includes('bot')){"hi dad");
  if(message.content === "!d bump" && bump_timeout==true){
      datafile[id] = {coins: 100};
      fs.writeFileSync(data, JSON.stringify(read_data, null, 2));`<@${id}> got 100 coins!`);
      var chillcoins = Number(datafile.coins) + 100;
      datafile[id] = {coins: chillcoins};
      fs.writeFileSync(data, JSON.stringify(datafile, null, 2));`<@${id}> got ${chillcoins} coins!`);
    bump_timeout = false;
    setTimeout(bump_switchtimeout, 5000);

function bump_switchtimeout(){
  bump_timeout = true;

client.on("ready", () => {
  console.log("bot is ready");


can someone explain the error to me?

>Solution :

You are passing a file rather than a path string. Try changing it to:

var read_data = fs.readFileSync("./userdata.json");

Leave a Reply Cancel reply