Javascript 让Discord机器人执行Ubuntu命令
我想让Discord机器人在看到类似“!t start”的消息时执行命令(sudo service terraria start)。我看过这本指南,我知道如何让机器人知道你何时发送某条消息,但我不知道如何让它执行命令。我将复制我的index.js。 谢谢大家!Javascript 让Discord机器人执行Ubuntu命令,javascript,bots,discord,Javascript,Bots,Discord,我想让Discord机器人在看到类似“!t start”的消息时执行命令(sudo service terraria start)。我看过这本指南,我知道如何让机器人知道你何时发送某条消息,但我不知道如何让它执行命令。我将复制我的index.js。 谢谢大家! const client = new Discord.Client() client.on("ready", () => { console.log(`Logged in as ${client.user.tag
const client = new Discord.Client()
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`)
})
client.on("message", msg => {
if (msg.content === "Ping") {
msg.reply("Pong!")
}
})
Obviously at the end would be the token.
您可以尝试使用child\u进程
const { exec } = require("child_process");
exec("sudo service terraria start", (error, stdout, stderr) => {
if(error) { console.log(`error: ${error.message}`);
return;}
if(stderr){ console.log(`stderr: ${stderr}`);
return; }
console.log(`stdout: ${stdout}`);
});
有关更多详细信息,请参阅