首页 > 解决方案 > 将 discord.js bot 转换为 exe

问题描述

我有一个工作不和谐的机器人,但我想把它编译成一个.exe文件。怎么做?我尝试使用pkgand nexe,但两者都没有正确使用。Nexe 甚至没有开始给我一些奇怪的错误,我在阅读文档和互联网上的一些讨论后无法修复这些错误。 Error: https://github.com/nexe/nexe/releases/download/v3.3.3/windows-x64-14.8.0 is not available, create it using the --build flagError: vcbuild.bat nosign release x64 exited with code: 1。效果更好,pkg我得到并exe归档,但它似乎不起作用:我有这段代码,其中 bot 是我的不和谐客户端。

bot.on('ready', () => 
{
    console.log(bot.guilds.cache.toJSON());
    bot.guilds.cache.forEach((gui) =>
    {
        console.log(gui.id + ' ' + gui.name + ' ' + gui.memberCount);
    });
    console.log('Bot started!');
});

当我使用 启动它时,它会提供一台服务器,但如果我执行创建的文件,node index.js它不会提供任何服务器,尽管机器人会联机。exe我的package.json样子是这样的:

{
  "name": "sth",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "pkg": {
    "assets": [ "jsons/**/*", "config.json" ]
  },
  "bin": "index.js",
  "author": "",
  "license": "ISC",
  "dependencies": {
    "discord.js": "^12.4.1"
  }
}

我究竟做错了什么?为什么机器人启动了,但似乎什么也做不了?我错过了什么?

标签: node.jsdiscord.jsexe

解决方案


我不知道您可以使用的.exe文件代码但是您可以使用.bat文件并将其放在桌面上并创建快捷方式或将其放在shell:startup您想要编写的位置

@echo off
node "js file path"

推荐阅读