首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在discord.js中关闭正在运行的子进程

在discord.js中关闭正在运行的子进程
EN

Stack Overflow用户
提问于 2022-05-01 18:49:26
回答 2查看 184关注 0票数 0

我在试图杀死/访问一个进程。它应该启动另一个机器人,同时也能杀死它。这就是我所做的。

代码语言:javascript
运行
复制
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}`)
        })

        
}
}

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

代码语言:javascript
运行
复制
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或在变量中保存一些东西来访问进程吗?(谢谢你的帮助;)

EN

回答 2

Stack Overflow用户

发布于 2022-05-01 18:58:00

这将终止您的程序。

代码语言:javascript
运行
复制
process.exit()
票数 0
EN

Stack Overflow用户

发布于 2022-10-27 19:43:22

添加process.exit()

像这样

代码语言:javascript
运行
复制
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()
    })

}
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72079540

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档