javascript - 当 bot DM 用户收集响应时,消息收集器不会启动
问题描述
因此,这与上一个问题(上一个问题)有关好像消息收集器没有启动?机器人向用户发送消息,控制台中没有任何内容,仅此而已。您可以整天回复机器人,它不会收集并发送到频道ID。任何指针?
这是我相信它可能围绕的代码:
collector.on('collect', (message, col) => {
console.log("Collected message: " + message.content);
counter++; ```
And here is all of the code (just in case it actually doesn't revolve around that):
``` if(message.content.toLowerCase() === '&reserveupdate') {
message.author.send('**Thanks for updating us on the reserve. Please enter what you are taking from the reserve below this message:**');
let filter = m => !m.author.bot;
let counter = 0;
let collector = new discord.MessageCollector(message.author, m => m.author.id, filter);
let destination = client.channels.cache.get('my channel id');
collector.on('collect', (message, col) => {
console.log("Collected message: " + message.content);
counter++;
if(counter === 1) {
message.author.send("**Thanks for updating us on the reserve, it is highly appreciated.**");
collector.stop();
}
解决方案
我认为您创建消息收集器的方式可能是错误的。
根据文档,您应该这样做:
const filter = m => !m.author.bot;
// If you are in an async function :
const channel = await message.author.createDM();
// Paste code here
// Otherwise :
message.author.createDM.then(channel => {
// Paste code here
});
// Code to paste :
const collector = channel.createMessageCollector(filter, { max: 1, time: 60000 });
collector.on('collect', msg => {
// ...
});
希望这将帮助您解决您的问题!:)
推荐阅读
- linux-kernel - Linux 是否在 mmap() 之后立即为进程分配内存?
- java - 对象是否应该与主 Activity 交互?
- python - 从 JSON 文件中提取名称
- python-3.x - 使用 Python 3.6 覆盖 Image Exif 中的 GPS 坐标
- scala - Swagger 工件在外部库中,但 IntellIJ 看不到
- teradata - TPT 脚本在运行时加载另一个文件
- react-admin - 如何在反应管理员中获得自定义操作的响应
- javascript - 如何在执行代码之前遍历某个类的所有元素?
- javascript - Openlayers 不重新投影 WMS 查询
- sql - 在 ORACLE 中创建视图