[英]How do I send a message to all guilds in discord.js with v12+ (12.0.0 and up)
if (command === "sendguildmessages") {
if (message.author.id === "231956829159161856") {
var guildList = client.guilds.array();
try {
guildList.forEach(guild => guild.defaultChannel.send("messageToSend"));
} catch (err) {
console.log("Could not send message to a (few) guild(s)!");
}
} else {
message.reply(`You cant do that!`)
}
} else
我嘗試使用 v11.2 但那是一個 KO 它說它已經過時並且需要更新。 我可以用此代碼替換什么?
defaultChannel()
已經被棄用並且沒有替代品。 並且您需要在發送消息的位置指定通道,但是由於某些服務器具有唯一的通道名稱,因此它不會工作......除非它們都具有相同的通道名稱並保持不變(有些偷看更改名稱一般的)。
好吧..我為它編寫了一個代碼(如果頻道名稱為“general”則有效)
if (command === "sendguildmessages") {
if (message.author.id === "231956829159161856") {
try {
let toSay = "messageToSend"
this.client.guilds.map((guild) => {
let found = 0
guild.channels.map((c) => {
if (found === 0) {
if (c.type === "text") {
if (c.permissionsFor(this.client.user).has("VIEW_CHANNEL") === true) {
if (c.permissionsFor(this.client.user).has("SEND_MESSAGES") === true) {
c.send(toSay);
found = 1;
}
}
}
}
});
});
}
catch (err) {
console.log("Could not send message to a (few) guild(s)!");
}
} else {
message.reply("You cant do that!")
}
}
取自: https ://github.com/itsYuuki/SmoreBot/blob/master/commands/control/gann.js
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.