Hello i'm getting this error when trying to access values from a function.
node:events:505
throw er; // Unhandled 'error' event
^
TypeError: createInvoice is not a function or its return value is not iterable
at Client.<anonymous> (C:\Users\Utente\Desktop\sito\InvoiceBot\index.js:101:63)
at Client.emit (node:events:527:28)
at InteractionCreateAction.handle (C:\Users\Utente\Desktop\sito\InvoiceBot\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at Object.module.exports [as INTERACTION_CREATE] (C:\Users\Utente\Desktop\sito\InvoiceBot\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\Utente\Desktop\sito\InvoiceBot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:354:31)
at WebSocketManager.<anonymous> (C:\Users\Utente\Desktop\sito\InvoiceBot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:238:12)
at WebSocketManager.emit (C:\Users\Utente\Desktop\sito\InvoiceBot\node_modules\@vladfrangu\async_event_emitter\dist\index.js:282:31)
at WebSocketShard.<anonymous> (C:\Users\Utente\Desktop\sito\InvoiceBot\node_modules\@discordjs\ws\dist\index.js:1103:51)
at WebSocketShard.emit (C:\Users\Utente\Desktop\sito\InvoiceBot\node_modules\@vladfrangu\async_event_emitter\dist\index.js:282:31)
at WebSocketShard.onMessage (C:\Users\Utente\Desktop\sito\InvoiceBot\node_modules\@discordjs\ws\dist\index.js:938:14)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:384:10)
at processTicksAndRejections (node:internal/process/task_queues:85:21)
C:\Users\Utente\Desktop\sito\InvoiceBot>
This is the function where i'm returning from:
function createInvoice(item_name, note_message, quantity, cost, payer_email){
let create_invoice_json = {
"merchant_info": {
"email": config.emailAddress,
"business_name": config.business_name,
},
"billing_info": [
{
"email": payer_email,
}
],
"items": [
{
"name": item_name,
"quantity": quantity,
"unit_price": {
"currency": "USD",
"value": cost,
}
},
],
"note": note_message,
}
paypal.invoice.create(create_invoice_json, function (error, invoice) {
if (error) {
throw error;
} else {
//console.log(invoice)
return [invoice.id, invoice.status, invoice.billing_info[0], invoice.items[0], invoice.items[1], invoice.invoice_date, invoice.total_amount[1]]
}
});
}
And this is how i want to access the values:
const [id, status, payer, item, q, date, price] = createInvoice(item_name, note_message, quantity, cost, payer_email)
I think it should be correct but its returning me that error...