Answers for "send message to all servers discord.js"

1

send message to all servers discord.js

// Using v11.2 of discord.js, should work with v12 too.

const discord = require('discord.js');
const client = new discord.Client();

// So you can see when it's ready
client.on('ready', () => {
    console.log('On Discord!');
});

client.on('message', () => {
    if (message.content === "!sendguildmessages") {
        var guildList = client.guilds.array();
        try {
            guildList.forEach(guild => guild.defaultChannel.send("messageToSend"));
        } catch (err) {
            console.log("Could not send message to " + guild.name);
        }
    }
});
Posted by: Guest on January-03-2021

Code answers related to "send message to all servers discord.js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language