我知道可能有一个重复的问题,但是我一直在阅读并且非常努力地理解和弄清楚如何将变量从命令模块传递到如下所示的事件模块中。
命令:
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('');
});
}
事件:
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) {};
我希望将embedid,embed2id等传递给事件模块,以便我可以按发送RichEmbed()时生成的消息ID进行过滤。
预先感谢,我已经圈了好几天了!
答案 0 :(得分:0)
因此,我通过研究出口的实际情况(实际上应该是我做的第一件事)来弄清楚了,
What is the purpose of Node.js module.exports and how do you use it?
使用在这里获得的信息,我对活动进行了以下更改:
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.