[英]How do I send a message to a channel in a specific Server
所以我希望機器人等待 DM 響應,它會從響應中獲取某些細節並將其粘貼到特定的服務器中。 我不知道如何將消息發送到特定服務器中的通道。
為了讓您向特定Guild
(服務器)上的特定Channel
發送消息,您需要首先知道我們“談論”的是哪個Guild
。
您可以通過多種方式聲明Guild
object,例如,如果您可以訪問Guild
的名稱,則可以通過在機器人的緩存公會(包括機器人所在的服務器)上找到它來聲明它。
假設您收到的 DM 始終將Guild
的名稱作為其最后一個“單詞”,並將Channel
名稱作為倒數第二個。
client.on("message", function(message) {
if(message.channel.type == "dm") { // Checks if the message was received through DM and not through some other channel
const words = message.content.split(' ');
const guildName = words[word.length - 1]; // Declares guildName as being the last word from the message
const channelName = words[word.length - 2]; // Equally, channelName is the second to last word
const recipientGuild = client.guilds.cache.find(guild => guild.name == guildName);
if(recipientGuild) {
const recipientChannel = guildName.channels.cache.find(channel => channel.name === channelName);
if(recipientChannel) recipientChannel.send(message.content);
else console.log("There is no channel with that name in that guild!");
}
else console.log("There is no cached guild with that name!");
}
});
希望這將使您對需要做什么有所了解。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.