简体   繁体   中英

discord.js || dm users with certain role

I want to add a function to my bot that would dm every person with a certain role, for ex.

&dmrole [role] [message]

I have no idea how to do that

Thanks for your help!

You need to grab the users in the role and then loop through them and DM them:

if (!args[0]) return message.reply('you need to provide a role')
if (!args[1]) return message.reply('you need to provide a message')
const role = message.mentions.roles.first()
message.guild.roles.cache.get(role.id).members.forEach(member => member.send(args[1]))

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