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

276
Vistas
Discord JS v12 Function Problem (My function is not getting recognized properly)

I have a problem importing/writing a function which calculates Currency A into Currency B. The problem is that the function is not recognized properly. My Function:

async function convertRMB(inputAmount) {
    const fetch = require("node-fetch");
    try {
        const responseRMB = await fetch('http://www.floatrates.com/daily/cny.json');
        const dataRMB = responseRMB.json();

        const rateEUR = dataRMB.eur.rate
        const rateUSD = dataRMB.usd.rate

        const RMBinEUR = Number(inputAmount) * Number(rateEUR)
        const RMBinUSD = Number(inputAmount) * Number(rateUSD)


        return RMBinEUR;
    } catch (err) { console.log(err) }
}


module.exports = {convertRMB};

The Class im using the function in:

const Discord = require('discord.js');
const convertRMB = require('../functions/convertRMB');

module.exports.run = async (bot, message, args) => {
    var inputAmount = args.join(' ');

    const amountEUR = convertRMB(inputAmount);

    const embed = new Discord.MessageEmbed()
        .setDescription(`${inputAmount}RMB = ${amountEUR}€`)
        .setFooter("© CSGO Library")
    message.channel.send(embed);

    convertRMB(inputAmount);

};

module.exports.help = {
    name: `rmb`
}

The Error im getting: "TypeError: convertRMB is not a function"

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

0

As the error says, "convertRMB" is not a function: it is the export object of your file convertRMB.js. You exported the function convertRMB() as a function of module.export, or to be clearer, is the same thing as:

module.export.convertRMB = function (input) {...};

To obtain what you want, that is to export the function as an anonymous one, you should do something like this:

module.exports = function (input) {...};

Or, using your code, you can use the export object that you have:

module.exports.run = async (bot, message, args) => {
    var inputAmount = args.join(' ');

    const amountEUR = convertRMB.convertRMB(inputAmount);

    const embed = new Discord.MessageEmbed()
        .setDescription(`${inputAmount}RMB = ${amountEUR}€`)
        .setFooter("© CSGO Library")
    message.channel.send(embed);

    convertRMB.convertRMB(inputAmount);

};

Here you can find some useful example to better understand the module.export dynamics.

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