Reputation: 1
currently creating a bot using discord.js that uses a cron-job to dm people a certain message regularly. The cron-job code itself works, I tried by logging. The problem in my code is when I try to actually dm people using the code, it doesn't work. I have looked around and still have no idea how to do this, I'v tried recycling some code I found on here which didn't work.
message.guild.roles.cache.get('[ROLE-ID]').members.array.forEach(member =>
{
message.member.send('[MESSAGE]').catch.console.error();;
});;
Upvotes: 0
Views: 63
Reputation: 8412
You're misusing a lot of functions/properties in this code. Make sure to always look at the discord.js docs to see how to use some of the methods.
First of all, Collection#array()
is a function. Second of all, you don't actually need Collection#array()
because Collection#forEach()
already exists with the same exact* functionality.
*for your use case
Third of all, even though you're using member
as a parameter in the forEach()
function, you're still using message.member
in the code. This will just send the same message to the message author per the number of people in that role.
Fourth of all, Promise#catch()
is a function and console.error()
should go inside of it, not be attached as a property.
Guides to understand promises:
Finally, mass dming people is a very bad idea unless there are minimal users using that role. Discord can easily ban your bot, as it's against the TOS (again, it depends on the amount of people0.
Upvotes: 1