Code that worked on Replit doesn't work in VSC

const tmi = require('tmi.js');

// Define configuration options
const opts = {
  identity: {
    username: 'BormBot',
    password: 'cut out for a reason'
  },
  channels: [
    'Epicurious__'
  ]
};

// Create a client with our options
const client = new tmi.client(opts);

const jsonFile = require('./link.json');
const fs = require('fs');
const mongoose = require('mongoose');
// Register our event handlers (defined below)

client.on('connected', onConnectedHandler);

// Connect to Twitch:
client.connect();


client.on('message', (channel, tags, msg, self, target) => {
  if (self) return;


  //start of geoguessr commands
  const link = {
    "link": ""
  };
  if (msg.startsWith('!geolink')) {


    if (tags.badges.broadcaster == 1) {
      
      const arguments = msg.split(/[ ]+/)
      if (arguments[1]) {
        let link = arguments[1];
        

        const data = JSON.stringify(link);

        fs.writeFile('./link.json', data, (err) => {
          if (err) {
            throw err;
          }
          console.log("JSON data is saved.");

        });
        
            client.say(channel, link);
           
      } else {
        console.log("no args");
      }



    }




  }
  if (msg.startsWith('!game')) {

    // read JSON object from file
    fs.readFile('./link.json', 'utf-8', (err, data) => {
      if (err) {
        throw err;
      }

      // parse JSON object
      const linkDone = JSON.parse(data.toString());

      // print JSON object
      client.say(channel, `The link for the current geoguessr game is: ${linkDone}`);
      console.log(`${linkDone}`);
    });



    }
 //end of geoguessr commands

});

// Called every time the bot connects to Twitch chat
function onConnectedHandler(addr, port) {
  console.log(`* Connected to ${addr}:${port}`);
}


Basically, my code worked completely fine in replit, but now it doesnt work in a vsc folder. my replit version also suddenly can’t send any messages anymore. it sends all the console.logs but the client.say stuff it just skips without an error.

usernames should be all lower case.

I don’t know if tmi.js auto/forces this.

Changed it to ‘bormbot’ but it still doesn’t give me any messages in chat. image

image is console

Then you’ve reached the limot of my ability to help with TMI.js

Since I don’t use the lib.

You’ll need to enable some logging to log all inbound and outbound messages to see whats coming too/from the server, which TMI.js will hide from you since it does the lifting for you.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.