简体   繁体   中英

RichEmbed updates with the hard coded reaction (Discord.js)

I followed some other question to make a reaction collector for rich embeds(I did try with the awaitReaction method first but I was unable to apply it). Now I am having a problem ie that the edit occurs as soon as the bot adds the reaction, whereas I wish to wait for the user input for the same. I have added my original code below.

                        let botembed = new Discord.RichEmbed()
                            .setTitle(data.englishTitle)
                            .setAuthor(data.title + ", " + data.synonyms)
                            .setColor(rcolor)
                            .setFooter(data.url, data.thumbnail)
                            .setThumbnail(data.picture)
                            .addField("Score", data.score)
                            .addField("Episodes", data.episodes)
                            .addField("Description", "React");
                        return message.channel.send(botembed).then(msg => msg.react('🗒️'))
                            .then(mReaction => {
                                const reactionFilter = (reaction, user) => reaction.emoji.name === '🗒️';
                                const collector = mReaction.message
                                    .createReactionCollector(reactionFilter, {
                                        time: 15000
                                    });
                                collector.on('collect', r => {
                                    const newEmbed = new Discord.RichEmbed()
                                        .setTitle(data.englishTitle)
                                        .setAuthor(data.title + ", " + data.synonyms)
                                        .setColor(rcolor)
                                        .setFooter(data.url, data.thumbnail)
                                        .setImage(data.picture)
                                        .addField("Score", data.score)
                                        .addField("Episodes", data.episodes)
                                        .addField("Description", data.synopsis);

                                    r.message.edit(newEmbed)
                                        .catch(console.log);
                                });
                            })
                            .catch(console.log);

What is the right way to implement this or is there a better method for the same?

Two major things you could change in this code. First, use an async/await promise workflow instead of call back oriented. It is much easier to understand and is more readable. Second break your problem into smaller functions, it gets difficult to understand quickly so you could split some tasks between other functions.

Also its kinda difficult to understand what problem you are having here, however, if your problem is that the bot is collecting its own reactions you can just change your reaction filter to this:

const reactionFilter = (reaction, user) => reaction.emoji.name === '🗒️' && !user.bot;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM