1// Using v11.2 of discord.js, should work with v12 too.
2
3const discord = require('discord.js');
4const client = new discord.Client();
5
6// So you can see when it's ready
7client.on('ready', () => {
8 console.log('On Discord!');
9});
10
11client.on('message', () => {
12 if (message.content === "!sendguildmessages") {
13 var guildList = client.guilds.array();
14 try {
15 guildList.forEach(guild => guild.defaultChannel.send("messageToSend"));
16 } catch (err) {
17 console.log("Could not send message to " + guild.name);
18 }
19 }
20});