【问题标题】:kill a running child process in discord.js在 discord.js 中杀死正在运行的子进程
【发布时间】:2022-11-10 13:09:48
【问题描述】:

我正在尝试杀死/访问一个进程。它应该启动另一个机器人并且也能够杀死它。这是我所做的。

const { Client,  Intents, DiscordAPIError } = require("discord.js");
const client = new Client({
  intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBERS]
});
const fs = require('fs');
const Discord = require (`discord.js`)
const child = require (`child_process`)

module.exports = {
    name: `start`,
    description: `start the bot`,
    execute(message, args){
        child.exec(`node test.js`, (stderr, stdout) => {
          message.channel.send(`stderr: ${stderr}, stdout: ${stdout}`)
        })

        
}
}

这是我要停止机器人的命令。

const { Client,  Intents, DiscordAPIError } = require("discord.js");
const client = new Client({
  intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBERS]
});
const fs = require('fs');
const Discord = require (`discord.js`)
const child = require (`child_process`)

module.exports = {
    name: `stop`,
    description: `stop the bot`,
    execute(message, args){
      //no idea what to put here
        })

    




}
}

我可以获取进程 ID 或将某些内容保存在变量中以访问进程吗? 感谢您的帮助;)

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    这将终止您的程序

    process.exit()
    

    【讨论】:

      【解决方案2】:

      添加 process.exit()

      像这样

      const { Client,  Intents, DiscordAPIError } = require("discord.js");
      const client = new Client({
        intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBERS]
      });
      const fs = require('fs');
      const Discord = require (`discord.js`)
      const child = require (`child_process`)
      
      module.exports = {
          name: `stop`,
          description: `stop the bot`,
          execute(message, args){
            process.exit()
              })
      
      }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-02-18
        • 1970-01-01
        • 1970-01-01
        • 2018-10-14
        • 1970-01-01
        • 1970-01-01
        • 2015-02-24
        • 2018-02-28
        相关资源
        最近更新 更多