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"))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.