Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

273
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!