Trying to add; give member unverified role

This code below checks when a member is added to my discord server, if they’ve previously verified before give them Verified + Group role, I am trying to add if they haven’t verified before give them the unverified role.

client.on("guildMemberAdd", async member => {
    try {
        const check = await fetch(`https://${site}/check.php?discord_id=${member.id}&get=roblox`, {
            method: "GET"
        });
        const id = await check.text();
        const account = await fetch(`https://users.roblox.com/v1/users/${id}`, {
            method: "GET"
        });
        const json = await account.json();
        if (typeof json !== "undefined" && typeof json.name !== "undefined") {
            member.setNickname(json.name);
            member.roles.add(member.guild.roles.cache.find(found => found.name === "Verified").id.toString());
            const roles = await fetch(`https://groups.roblox.com/v2/users/${json.id}/groups/roles`, {
                method: "GET"
            });
            const data = await roles.json();
            for (var i = 0; i < data.data.length; i++) {
                const group = data.data[i];
                if (group.group.id == "1014948") {
                    const role = member.guild.roles.cache.find(role => role.name === group.role.name);
                    if (role == null) {
                        member.guild.roles.create({
                            name: group.role.name,
                        }).catch(console.log).then(role => {
                            member.roles.add(role.id);
                        });
                    } else {
                        member.roles.add(role.id);
                    }
                }
            }
        }
    } catch (error) { console.log(error); }
});
1 Like

Do you got any errors in output?

No, that code is fine. I’m just trying to add on at the end give member unverified role. But I’m having trouble on how.

What module are you using?

I am using Discord.js

Js is one of my weaknesses, do you know how to add roles in discord.js?

I do, but I am struggling with what to start, “else if” “try else” I am confused on that part.

Try adding print statements in your code & see what happens when this or that happens.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.