0

I know there may be a duplicate question but I've been reading and really struggling to understand and figure out how to pass a variable from a command module into an event module shown below.

Command:

exports.run = async (client, message, args) => {
    const embed = new Discord.RichEmbed()
        .addField(':heart:', `${xb.toString()}`, true)
        .addField(':black_heart:', `${ps.toString()}`, true)
        .addField(':yellow_heart:', `${nin.toString()}`, true)
        .addField(':purple_heart:', `${pcmr.toString()}`, true)

    message.channel.send(embed).then(async msg => {
        let embedid = msg.id;
        module.exports.embedid = embedid;
        await msg.react('❤');
        await msg.react('');
        await msg.react('');
        await msg.react('');
    });
}

Event:

module.exports = async (client, messageReaction, user) => {
    const message = messageReaction.message;
    const channel = message.guild.channels.find(c => c.name === 'role-assignment');
    const member = message.guild.members.get(user.id);
    if(member.user.bot) return;

    const xb = message.guild.roles.get('540281375106924555');
    const ps = message.guild.roles.get('540296583632388115');
    const nin = message.guild.roles.get('540296630260203520');
    const pcmr = message.guild.roles.get('540296669733060618');

    if(['❤', '', '', ''].includes(messageReaction.emoji.name) && message.channel.id === channel.id && messageReaction.message.id === embedid) {};

I'm hoping to pass embedid, embed2id and so on to the event module so I can filter by the message ID that is generated when sending the RichEmbed()

Thanks in advance, I've been running in circles for days!

Bret Hawker
  • 99
  • 1
  • 11
  • Can you please edit your code to show proper indentation? Hard to read as it is. – jfriend00 Jan 31 '19 at 21:58
  • Also, it generally does you no good to assign to `module.exports` in an async callback. Anyone who loads your module won't know when that value will appear (it will not be there when they first load the module). – jfriend00 Jan 31 '19 at 21:59
  • Sorry, thats been changed for you and I'm using this project to learn JS so my knowledge is still pretty limited – Bret Hawker Jan 31 '19 at 22:02
  • Also, nobody else will be loading or have any of my full code, its a private Discord.js bot – Bret Hawker Jan 31 '19 at 22:04

1 Answers1

0

So I figured it out by looking into what exports actually do, which really, should have been the first thing I did, here :

What is the purpose of Node.js module.exports and how do you use it?

Using the info learned here, I made the following changes to my event:

const e1 = require('../commands/startroles'); // At the top of my messageReactionAdd.js file before module.exports[...]

messageReaction.message.id === e1.embedid // added the e1. to import the variable.
Bret Hawker
  • 99
  • 1
  • 11