Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

187
Vistas
Handling [object Promise] from noblox.js in discord.js

Surprisingly difficult to find this on google...

So I'm making a discord bot with discord.js and connecting a noblox.js bot to it.

const nbx = require('noblox.js');
const { Client, Intents } = require('discord.js');
const { token } = require('./config.json');

const prefix = '!';

const client = new Client({ intents: [ Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES ] })
 
async function payout(userId, amount) {
    await nbx.setCookie('roblox cookie');
 
nbx.groupPayout(12845526, userId, amount, false);
console.log("paid " + amount + " robux to " + userId)
}

async function getUser(userId) {
    let username = await nbx.getUsernameFromId(userId);
    return username;
}
 
client.on("ready", () => {
 
    console.log("Bot is ready");
 
});
 
client.on("messageCreate", (message) => {
    if (!message.content.startsWith(prefix)) return;

    const args = message.content.trim().split(/ +/g);
    const cmd = args[0].slice(prefix.length).toLowerCase(); // case INsensitive, without prefix

    if (cmd === 'test') message.reply('Bot is online!');

    if (cmd === 'payout') {
        if (!args[3]) return message.reply('Correct usage: Group, Player, Amount');

        const username = getUser(args[2]);
        
        message.reply('Paid ' + args[3] + " robux to " + username);

        //payout(userId, amount);
      }
    
});
 
client.login(token);

Payout is commented because I do not want to yet, I am just trying to make messaging work.

Output on discord when I type the !payout command:

Paid 1 robux to [object Promise]

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You have to await the getUser as it's an async function and returns a promise

const username = await getUser(args[2])

Note: you must change the messageCreate callback to asynchronous

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda