0
votes

I'm currently trying to create some sort of an announcement command for events or similar stuff. My issue currently is that it either sends the message X times to one server (X = the amount of servers the bot is in) or it just sends it to a random channel instead of the one that I wanted to send it in (I still don't know why that is).

module.exports.run = async (bot, message, args) => {
  async function announcement(guild, user) {
    const threshold = 0.85;
    const channel = message.guild.channels.cache.find((channel) => {
      const result = stringSimilarity.compareTwoStrings(
        channel.name.toLowerCase(),
        config.events
      );
      if (result >= threshold) {
        return true;
      }
      return false;
    });
    bot.guilds.cache.forEach((guild) => {
      console.log(guild.name);
      //This is where I would send the message
      //channel.send('message here')
    });
  }
  async function myFunc() {
    for (let guild of bot.guilds.cache) {
      const response = true;
      if (response) {
        announcement();
      }
    }
    resolve();
  }
};

myFunc();

Also yes I know, my promise is rather useless currently, still gotta do some stuff with that.

1

1 Answers

0
votes

You would need to find a channel for each guild, so it would have to be created like this

bot.guilds.cache.forEach((guild) => {
 console.log(guild.name);

 //This would make the client to send a message "Announcement!" to a channel named "news" in every server, if such a channel didn't exist in a guild, the message wouldn't be sent for that exact guild
 try {
  guild.channels.cache.find((x) => x.name == 'news').send('Announcement!');
 } catch {
  //If message couldn't be sent
  console.log("Message wasn't sent for " + guild.name);
 }
});