1 year ago

#245

test-img

Epicurious

Code that worked on Replit doesn’t work in VSC

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.

    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}`);
}

console

Also on twitch developer forum: 2

On twitch developer forum there hasn't been an answer yet, hence why I'm also putting it on here. Hopefully I can find an answer, also, maybe add a tag for tmi.js

node.js

irc

twitch

0 Answers

Your Answer

Accepted video resources