Run a python script in javascript

Asked

Viewed 144 times

0


client.on("chat", function(channel, user, message, self){
    if(message === 'Olá'){
        client.action("ythezack", user["display-name"] + " Seja bem vindo!");}
    if(message === '!Nick'){
        client.action("ythezack", "Meu nick no lol é: Sixxxty me adicione lá!")
    }
    if(message === '!MeuAmigo'){
        MeuAmigo++;
        client.action("ythezack", "Sixx já disse meu amigo " + MeuAmigo + " vezes!")}
    if(message === '!saranking'){


    }       


});

I made this code in javascript, for bot on Twitch.Tv, and would like to know in the case of if(message===!saranking) It would be possible to run a python code there?

  • You are running that code on Node or browser?

  • Node, write in sublime and run in cmd

1 answer

0

You can use to run Nodes. I’m not sure what the logic of your application is and what asynchronous threads you need to have but an example would be:

const { spawn } = require('child_process');
const processoPython = spawn('python',["caminho/para/ficheiro.py", arg1, arg2, ...]);

processoPython.stdout.on('data', (data) => {
  // fazer algo
});

processoPython.stderr.on('data', (data) => {
  // gerir o erro
});

processoPython.on('close', (code) => {
  // o processo acabou
});

To insert into your application you have to take into account that callbacks are asynchronous and if/Else logic is not. I suggest chaining the continuation of this script after reply from end or if the stderr be called.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.