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:
Advertisement
Answer
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