'Discord.js how can bot ping when someone with a specific role leave

I made a bot and I want to add a feature to my bot. ping a specific room when people with a custom role leave the server. So, for example, we'll know when people with the "partner" role come out. I wanna write code in index.js.



Solution 1:[1]

Lemme tell you this isn't much related to discordjs itself, but the way discord client works. You should not probably ping a user who has left the server, as uncached users on mobile or any user may show as invalid user. Therefore you should log username#discriminator, or actually tag and then user id incase you want to keep the record of their IDs for future ping, etc.

Edit after you commented: There's guildMemberRemove event for your client bot. Info: https://discord.js.org/#/docs/discord.js/stable/class/Client?scrollTo=e-guildMemberRemove

It emits member object, and you can get that user's name, etc from that. You can make the bot dm you, or send a message in a specific channel, and ping you.

Important Notice: keep your bot private, in your server only, or else, add a if condition to check whether the member who left was from your specific server or not, or else the bot may log that user even if he didn't leave your own server.

Solution 2:[2]

In guildMemberRemove event you can specify the alert message. Check member has a role or not then send your message in right situation.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Dharman