jaredlyon / JareBot

A revisited JS project
GNU General Public License v3.0
5 stars 1 forks source link

Approval system fails to recognize users that have already been approved #27

Closed jaredlyon closed 4 years ago

jaredlyon commented 4 years ago

image image

Current code:

if (msg.channel.id == bot.config.welcomeChannel) {
            if (target != null) {
                if (!target.roles) {
                    var logEmbed = new Discord.MessageEmbed()
                        .setAuthor(msg.author.username, msg.author.avatarURL())
                        .addField('Member approved:', yup + ` **${target.username.toString()}#${target.discriminator} (${target.id}) was approved.**`)
                        .setFooter(bot.user.username, bot.user.avatarURL())
                        .setTimestamp()
                        .setColor(3447003);

                    msg.mentions.members.forEach(member => {
                        member.roles.add(msg.guild.roles.cache.find(role => role.name === "• Customers")).then(member => {
                            channel.send({
                                embed: logEmbed
                            })
                            log.send({
                                embed: logEmbed
                            })
                        });
                    })
                } else if (target.roles) {
                    msg.reply("user has already been approved!");
                } else {
                    msg.reply("something went wrong!");
                }

Executed properly, the targeted user should not trigger the primary if statement due to their roles.

jaredlyon commented 4 years ago

Attempts to remedy the issue using a .cache.get method to probe the target user for a specific role have been unsuccessful due to (presumably) an inability to prompt a cache refresh. Specific code examples with attached error logs may be attached to the thread at a later time.

jaredlyon commented 4 years ago

Discord.js v12 includes an update to presence and server member intents, so this issue may resolve itself on its own with minor tweaks. See issue #30 for more info.

jaredlyon commented 4 years ago

Updated the if statements used in commit ca9c6b2, but now we're getting this really weird kickback error that has no discernable cause:

Screen Shot 2020-11-06 at 10 39 56 AM
jaredlyon commented 4 years ago

I ended up removing the role check entirely (1d87462); if duplicate logs become a problem then we'll revisit this issue in the future.

jaredlyon commented 4 years ago

It appears the same issue has also broken the j!ban command in moderation:

Screen Shot 2020-11-09 at 8 17 24 AM
jaredlyon commented 4 years ago

Verified the above commit's (9c7e1ef) fix:

Screen Shot 2020-11-09 at 10 22 58 AM

I'll try it for the original j!approve command next.

jaredlyon commented 4 years ago

Commit 35117e3 recreates the original undefined cache error throw:

Screen Shot 2020-11-09 at 10 59 35 AM
jaredlyon commented 4 years ago

Fixed by 74d3189:

Screen Shot 2020-11-09 at 12 22 07 PM

The problem was that I had been using .users instead of .members...