skip to Main Content

const statuses = [
 { name: "ABC", type: ActivityType.Streaming },
 { name: "DEF", type: ActivityType.Watching },
 { name: "GHI", type: ActivityType.Listening },
 { name: "JKL", type: ActivityType.Playing },
];
client.on('ready', (c) => {
  console.log(`✅ ${c.user.tag} is online!`);
  setInterval(() => {
    var newStatus = statuses[Math.floor(Math.random() * statuses.length)];
    client.user.setActivity(newStatus);
  }, 10000);
});

statuses.json

(nothing, so far)

I tried adding a JSON file (a random example shown below):

[{
name: "ABC", type: ActivityType.Streaming
name: "DEF", type: ActivityType.Watching 
name: "GHI", type: ActivityType.Listening
name: "JKL", type: ActivityType.Playing 
}]

But yet, I am still not sure how to call this into my main index.js file.

2

Answers


  1. Create a .json file with the information for example like this: [{name: "Orange", type: "fruit"}].

    Then import using FS in the main .js file like this:

    const fruits = JSON.parse(fs.readFileSync('fruits.json'));
    
    Login or Signup to reply.
  2. Create a statuses.json file in the same folder like this:
    (The numbers are enums for the ActivityType)

    [
     { "name": "ABC", "type": 1 },
     { "name": "DEF", "type": 3 },
     { "name": "GHI", "type": 2 },
     { "name": "JKL", "type": 0 }
    ]
    

    Then in your code import your .json file:

    const statuses = require('./statuses.json');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search