I can't understand why my message doesn't send to every user that decided to be notified. It only sends to one. If there are any documents about quick.db to fix it of course let me know.
Here's the notify.js code
module.exports = {
name: 'notify',
description: 'Notify people when a new update is released',
category: "Notified",
execute(client, message, args, Discord) {
if(message.member.user.id === '601364286731714591'){
const db = require('quick.db')
let notification = db.get(`notifiedusers_${message.author.id}`);
if(notification === null) {
return message.channel.send('Nobody is notified for any updates')
}
const content = args.join(" ")
if(!content) return message.channel.send('What would be the content of the Update Be ?')
const newEmbed = new Discord.MessageEmbed()
.setColor('#b5b5b5')
.setTitle('Update')
.setDescription(`${content}`)
message.channel.send('Notifying everybody that desiced to be notified')
try{
const chx = client.users.cache.get(notification)
chx.send({embeds: [newEmbed]})
}finally{
message.channel.send('Everybody was notified')
}
}else{
return
}
}
}
const chx = client.users.cache.get(notification)
chx.send({embeds: [newEmbed]})
In this function you can only use 1 id to get the user object of the person, if you have an array of people's ids which you can store using db.push you can then get every person's id and send it to each person
for (const id of <array_of_id>){
const chx = client.users.cache.get(id)
chx.send({embeds: [newEmbed]})
}
Also, doing too many requests to discord's API will get you ratelimited so give a time to send to each user
for(const id of <array_of_id>){
const chx = client.users.cache.get(id)
chx.send({embeds: [newEmbed]})
// Wait 3000 milliseconds (3 minutes)
await new Promise(r => setTimeout(r, 3000));
}