javascript - Discord Bot 自动批量删除问题
问题描述
我正在设置一个 Discord 机器人,它将在 15 分钟的间隔内删除特定文本频道中的所有消息,但这些消息不会删除。
Client.on("message", async function(message) {
if(message.channel.id != "506258018032418817") return;
setInterval (function () {
var Trash = message.channel.fetchMessages({ limit: 100 }).then(
message.channel.bulkDelete(Trash));
}, 900000);
});
解决方案
您正在尝试访问该Trash
变量,但它不包含您认为的内容。 Trash
被分配了代表函数链最终结果的 Promise。
您应该将结果传递给then()
并将其用作bulkDelete()
调用的参数。
Client.on("message", async function(message) {
if(message.channel.id != "506258018032418817") return;
setInterval (function () {
message.channel.fetchMessages({ limit: 100 }).then(
function(deleteThese) { message.channel.bulkDelete(deleteThese); })
}, 900000);
});
请记住,此功能的逻辑并不合理。伪代码如下:
- 每当有消息发送到此特定频道时 - 排队一个计时器在 15 分钟内发生 - 15分钟后,从频道中删除100条消息
考虑如果发生这种情况会发生什么
1:00 Paul talks in channel
--- (timer 1 is started)
1:01 Elizabeth responds
--- (timer 2 is started)
... < time passes > ...
1:14 Charles says something in the channel
... < timer 1 triggers; room is wiped > ...
1:15 Diane says something in response to Charles' deleted message
... < timer 2 triggers; room is wiped > ...
1:16 Charles asks Diane to repeat what she just said
您可能希望更改在fetchMessages()
通话中打发时间的方法,以便仅删除 15 分钟或更早的消息。
推荐阅读
- python - 如何在 python 中将 COLORREF 从 GetPixel() 转换为 RGB?
- database - 从数据库切换运费和账单值
- c++ - 无法为 atmega 2560 编译 arduino 草图 vscode
- java - Java,访问类方法的问题
- javascript - 将动态字段数据从一个组件发送到另一个组件
- pandas-groupby - 按特定的 id 子集分组
- javascript - 有什么办法可以停止加载 mapbox gl 图层吗?
- swift - 我该如何解决:UILabel.text 只能在主线程中使用
- tensorflow - 如何计算自定义数据集上的 TF 对象检测 API 精度?
- python - 尝试打印值时,tensorflow会话停止