我正在寻找如何向所有服务器和特定频道发送消息的方法,您能帮我吗?
答案 0 :(得分:1)
// Looping through all the guilds.
client.guilds.cache.forEach(guild => {
// Getting the channels of the guild.
const channels = guild.channels.cache.map(channel => channel.name);
// Checking if the guild has a channel named "find-mdt".
if (!channels.includes("find-mdt")) {console.log(`Channel not found on ${guild.name}.`); return false;};
// Sending the message to the channel "find-mdt", if available.
guild.channels.cache.find(channel => channel.name == "find-mdt").send("My Message").then(() => {console.log(`Message sent to ${guild.name}`);}).catch(e => console.log(e));
});