I have made a Discord bot with Discord.js and MongoDB for my discord servers.
So in my MongoDB, I have the variable for a channel ID, which is a different channel in each of my 3 discords. With the code below, when I run the command, the message only get sent to the first discord channel in the database. Any idea's on what i'm doing wrong?
const Discord = require("discord.js");
module.exports.run = async (bot, message, args, settings, guild, channels) => {
if (message.channel.id === '123456789') {
bot.guilds.forEach(guild => {
const sayMessage = args.join(" ");
let sicon = message.guild.iconURL;
let serverembed = new Discord.RichEmbed()
.setTitle("**Announcement**")
.setFooter("from SpikyZA", sicon)
.setTimestamp()
.setColor("#5500FF")
.addField("Message", `${sayMessage}`);
//let testchannel = guild.channels.find(c => c.id === `${settings.notify}`);
bot.channels.get(`${settings.notify}`).send(serverembed);
});
}
};
module.exports.help = {
name:"test",
aliases: ["test"]
};```
if you're looking for a simple way to do it, try looping through the amount of items in the database, like this:
for(n = 0; n <= channelDB.length; n++){
let ch = bot.channels.get(channelDB.channels[n].id);
ch.send(embed);
}
or whatever similar code works with MongoDB
🤷♂️
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.