问题描述
我创建了一个使用 DiscordJS 来监控消息的机器人.例如:
I've created a bot using DiscordJS to monitor messages. For example:
client.on("message", function(message) { // Do stuff });
我想知道是否有一种可能的方法来获取在频道中当前消息对象之前立即发送的消息.
I would like to know if there is a possible way to fetch the message that was immediately sent before the current message object in the channel.
推荐答案
我想我通过这样做找到了一个令人满意的方法:
I think I've found a satisfactory method by doing something like this:
message.channel.fetchMessages({limit: 2}) .then(messageMappings => { let messages = Array.from(messageMappings.values()); let previousMessage = messages[1]; // do something with previous message }) .catch(error => Logger.log("error", "Error fetching messages in channel"))