StillPollex
StillPollex

Reputation: 3

Opening file with js

I'm trying to make a discord.js bot which whenever someone types a certain command on Discord, it opens a program on my PC:

client.on("message", (message) => {
    if (message.content == "!ping") {
        //here I want to open a program on my pc 
    }
});

Upvotes: 0

Views: 48

Answers (1)

Payton Doud
Payton Doud

Reputation: 56

Assuming you are using Node you can include the execFile function from the child_process package and just call it from the command line.

const { execFile } = require("child_process");
client.on("message", (message) => {
    if(message.content == "!ping") {
         execFile("<path to file>", ["optional arg1", "optional arg2"]);
    }
});

Or if you just want to run a command, just exec

const { exec } = require("child_process");
client.on("message", (message) => {
    if(message.content == "!ping") {
         exec("<shell command>", ["optional arg1", "optional arg2"]);
    }
});

Check out https://nodejs.org/api/child_process.html#child_processexeccommand-options-callback for documentation.

You may need to "npm install child_process"

Upvotes: 1

Related Questions