Twitter Bot To Post Random Tweets on Twitter(X) AuthV2 from Node.js

109 Views Asked by At

I have a Node.js code which is working at present to post a Tweet, but I need it to post a random one from a list. I see there are a lot of examples of this from the previous API V1 of Twitter but it needs to work with the latest V2...

Here is my code which is working to post one Tweet("Hello World!"):

require("dotenv").config({ path: __dirname + "/.env" });
const { twitterClient } = require("./twitterClient.js")
const CronJob = require("cron").CronJob;

const tweet = async () => {
  try {
    await twitterClient.v2.tweet("Hello World!");
  } catch (e) {
    console.log(e)
  }
}

const cronTweet = new CronJob("* * * * *", async () => {
  tweet();
});

cronTweet.start();
0

There are 0 best solutions below