Roirraw
Roirraw
DIAdiscord.js - Imagine a boo! 👻
Created by Roirraw on 8/5/2023 in #djs-questions
Building .exe file with pkg results in "Failed to make bytecode"
Hey, I'm trying to build my node discord.js project into .exe file for ease of use. I managed to do so with https://www.npmjs.com/package/pkg by simply running it with pkg . --targets node18-win-x64 and below configuration:
"pkg": {
"scripts": "commands/**/*.js"
}
"pkg": {
"scripts": "commands/**/*.js"
}
I got following warnings though:
> Warning Failed to make bytecode node18-x64 for file C:\snapshot\bounty-rune-bot\node_modules\file-type\index.js
> Warning Failed to make bytecode node18-x64 for file C:\snapshot\bounty-rune-bot\node_modules\file-type\core.js
> Warning Failed to make bytecode node18-x64 for file C:\snapshot\bounty-rune-bot\node_modules\file-type\supported.js
> Warning Failed to make bytecode node18-x64 for file C:\snapshot\bounty-rune-bot\node_modules\file-type\util.js
> Warning Failed to make bytecode node18-x64 for file C:\snapshot\bounty-rune-bot\node_modules\file-type\index.js
> Warning Failed to make bytecode node18-x64 for file C:\snapshot\bounty-rune-bot\node_modules\file-type\core.js
> Warning Failed to make bytecode node18-x64 for file C:\snapshot\bounty-rune-bot\node_modules\file-type\supported.js
> Warning Failed to make bytecode node18-x64 for file C:\snapshot\bounty-rune-bot\node_modules\file-type\util.js
and I have noticed that the .exe won't work without all node_modules copied into it's directory. I suspect it might be related to file-type not being bundled correctly, but maybe I'm missing something else. Thanks for help in advance.
5 replies
DIAdiscord.js - Imagine a boo! 👻
Created by Roirraw on 7/28/2023 in #djs-questions
User being displayed as [object Object]
Hey, I'm trying to display a leaderboard of users having the most gold saved in my sqlite database, here's my command:
async execute(interaction) {
const private = interaction.options.getBoolean(OPTION_PRIVATE);
const usersAmount = interaction.options.getInteger(OPTION_AMOUNT_OF_USERS);

const users = await Users.findAll({
order: [['balance', 'DESC']],
limit: usersAmount,
});
if (users.length === 0) {
await interaction.reply({ content: 'Everyone is broke :(', ephemeral: private });
}
else {
let message = '';
const limit = users.length < usersAmount ? users.length : usersAmount;

const rest = new REST().setToken(process.env.DISCORD_TOKEN);
const fetchUser = async id => rest.get(Routes.user(id));

for (let i = 0; i < limit; i++) {
const user = await fetchUser(users[i].user_id).catch(() => null);
message += `${i + 1}. ${user ? user.global_name : 'Unknown user'} - ${users[i].balance} gold.\n`;
}
await interaction.reply({ content: message, ephemeral: private });
}
},
async execute(interaction) {
const private = interaction.options.getBoolean(OPTION_PRIVATE);
const usersAmount = interaction.options.getInteger(OPTION_AMOUNT_OF_USERS);

const users = await Users.findAll({
order: [['balance', 'DESC']],
limit: usersAmount,
});
if (users.length === 0) {
await interaction.reply({ content: 'Everyone is broke :(', ephemeral: private });
}
else {
let message = '';
const limit = users.length < usersAmount ? users.length : usersAmount;

const rest = new REST().setToken(process.env.DISCORD_TOKEN);
const fetchUser = async id => rest.get(Routes.user(id));

for (let i = 0; i < limit; i++) {
const user = await fetchUser(users[i].user_id).catch(() => null);
message += `${i + 1}. ${user ? user.global_name : 'Unknown user'} - ${users[i].balance} gold.\n`;
}
await interaction.reply({ content: message, ephemeral: private });
}
},
Works fine with user.global_name but displaying just the user results in [object Object] in the message. Why is that? I thought that printing out user in the string literal or using .toString() method will automatically display the user as mention @username. What am I missing?
7 replies