DiscordJS Bot - How to get the message immediately before another message in a channel?(DiscordJS Bot - 如何在频道中的另一条消息之前立即获取消息?)
问题描述
我创建了一个使用 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"))
这篇关于DiscordJS Bot - 如何在频道中的另一条消息之前立即获取消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:DiscordJS Bot - 如何在频道中的另一条消息之前立即


基础教程推荐
- 如何添加到目前为止的天数? 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- npm start 错误与 create-react-app 2022-01-01