Jonas
Jonas9mo ago

Compile to exe

Every time I run my exe I get the following error, But when I start my code normally with node main.js it works without problems. This is my Code:
import Discord, { Guild } from "discord.js";
import inquirer from "inquirer";
import { discordChoose, getBotToken } from "../../../lib/discord/main.js";
import { getRole } from "../../../lib/helper.js";

export const bot = async () => {
const token = await getBotToken();
const client = new Discord.Client({
intents: [
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildMembers,
Discord.GatewayIntentBits.GuildIntegrations,
Discord.GatewayIntentBits.GuildVoiceStates,
Discord.GatewayIntentBits.MessageContent,
Discord.GatewayIntentBits.GuildMessages,
],
});

process.on("unhandledRejection", (error: any) => {
console.log(chalk.red("An error occurred:"));
if (error.message === "Used disallowed intents") {
console.log(
chalk.red(
"The bot needs the following intents to work:\n- MESSAGE CONTENT INTENT\n- SERVER MEMBERS INTENT"
)
);
} else {
console.log(chalk.red(error.message));
}
discordChoose();
return;
});

client
.login(token)
.then(() => {
choose(client);
})
.catch(() => {
console.log(chalk.red("Invalid token!"));
discordChoose();
return;
});
};
import Discord, { Guild } from "discord.js";
import inquirer from "inquirer";
import { discordChoose, getBotToken } from "../../../lib/discord/main.js";
import { getRole } from "../../../lib/helper.js";

export const bot = async () => {
const token = await getBotToken();
const client = new Discord.Client({
intents: [
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildMembers,
Discord.GatewayIntentBits.GuildIntegrations,
Discord.GatewayIntentBits.GuildVoiceStates,
Discord.GatewayIntentBits.MessageContent,
Discord.GatewayIntentBits.GuildMessages,
],
});

process.on("unhandledRejection", (error: any) => {
console.log(chalk.red("An error occurred:"));
if (error.message === "Used disallowed intents") {
console.log(
chalk.red(
"The bot needs the following intents to work:\n- MESSAGE CONTENT INTENT\n- SERVER MEMBERS INTENT"
)
);
} else {
console.log(chalk.red(error.message));
}
discordChoose();
return;
});

client
.login(token)
.then(() => {
choose(client);
})
.catch(() => {
console.log(chalk.red("Invalid token!"));
discordChoose();
return;
});
};
This is my package.json:
{
"type": "module",
"scripts": {
"start": "tsc && node dist/main.js",
"build": "deno compile dist/main.js"
},
"license": "ISC",
"devDependencies": {
"@types/figlet": "^1.5.8",
"@types/gradient-string": "^1.1.5",
"@types/inquirer": "^9.0.7",
"@types/node": "^20.10.0",
"typescript": "^5.3.2"
},
"dependencies": {
"axios": "^1.6.5",
"chalk": "^5.3.0",
"discord.js": "^14.14.1",
"dotenv": "^16.4.1",
"figlet": "^1.7.0",
"inquirer": "^9.2.12",
"nanospinner": "^1.1.0",
}
}
{
"type": "module",
"scripts": {
"start": "tsc && node dist/main.js",
"build": "deno compile dist/main.js"
},
"license": "ISC",
"devDependencies": {
"@types/figlet": "^1.5.8",
"@types/gradient-string": "^1.1.5",
"@types/inquirer": "^9.0.7",
"@types/node": "^20.10.0",
"typescript": "^5.3.2"
},
"dependencies": {
"axios": "^1.6.5",
"chalk": "^5.3.0",
"discord.js": "^14.14.1",
"dotenv": "^16.4.1",
"figlet": "^1.7.0",
"inquirer": "^9.2.12",
"nanospinner": "^1.1.0",
}
}
No description
5 Replies
Deno AI Helper
Deno AI Helper9mo ago
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the information you've provided in your message, there are a few things I can point out that might help you resolve the issue. Firstly, it seems like you are trying to compile a TypeScript project that uses Node.js-specific modules (like discord.js) with Deno. Deno and Node.js have different runtime environments and standard libraries, so a project written for Node.js will not work out of the box with Deno. Deno does not use node_modules or package.json, and it has its own set of APIs and module resolution strategy. The deno compile command is used to compile Deno projects into standalone executables, and it expects Deno-compatible code. Since your code and dependencies are written for Node.js, you cannot directly compile them with Deno. If you want to create an executable from your Node.js project, you would need to use a tool that is designed for Node.js, such as pkg or nexe. Please note that this advice is not based on the Deno documentation, and I would advise you to double-check the accuracy of the advice given. If you are looking to work with Deno, you would need to rewrite your code to be compatible with Deno's APIs and module system.
Antonio Sampaio
Antonio Sampaio9mo ago
are you using deno?
Jonas
Jonas9mo ago
i use node.js
akumaruь
akumaruь9mo ago
check if it works fine with deno run
Jonas
Jonas9mo ago
no