Reputation: 51
Can anyone help me? I don't know how to do this, but I want to make my bot send a message to every server it is in and if it doesn't have perms to do it, it can just ignore it. How do you do it?
Upvotes: 3
Views: 11856
Reputation: 81
// Using v11.2 of discord.js
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);
}
}
});
The Bot will send messages when you type !sendguildmessages into a channel the bot can read messages from.
Upvotes: 3