【发布时间】:2021-08-20 17:19:20
【问题描述】:
所以我希望机器人等待 DM 响应,它会从响应中获取某些详细信息并将其粘贴到特定服务器中。我不知道如何将消息发送到特定服务器中的频道。
【问题讨论】:
-
你能显示你的代码吗
标签: javascript node.js discord discord.js
所以我希望机器人等待 DM 响应,它会从响应中获取某些详细信息并将其粘贴到特定服务器中。我不知道如何将消息发送到特定服务器中的频道。
【问题讨论】:
标签: javascript node.js discord discord.js
为了让您向特定Guild(服务器)上的特定Channel 发送消息,您首先需要知道我们“谈论”的是哪个Guild。
您可以通过多种方式声明Guild 对象,例如,如果您可以访问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!");
}
});
希望这能让您了解您需要做什么。
【讨论】: