我正在使用 Discord js 制作一个 Discord 机器人。 bot 的作用是在个人消息中向用户发送消息,然后等待用户响应 5 分钟。如果用户没有向会员发送任何信息,则机器人会发送一条消息,说明请求已被拒绝,因为他们没有发送任何电子邮件 ID。我正在使用 discord.js 收集器 npm 包来获取消息并将其发送给用户。我遇到的问题是,如果用户没有输入任何内容,机器人会在 30 秒后向用户发送回复。我不想要那个。我希望机器人在发送请求被拒绝消息之前等待 5 分钟。这是我的代码的样子。
message.reply("Please check your DM to verify your email id");
const filter = (m) => m.author.id === message.author.id;
const botMessage = await message.author.send("Enter your registered email Id please?");
const userMessage = await MessageCollector.asyncQuestion({
botMessage,
user: message.author.id,
time:300000 // milliseconds
}).catch(()=>{
message.author.send("Request Denied because you did not responded with a registerd email ID. You can request again!");
return 0;
});
我还使用了 discord js 库来实现自己的参数,例如 idle,但我仍然收到错误消息。这是我的代码在那里的样子。
message.reply("Please check your DM to verify your email id");
const filter = (m) => m.author.id === message.author.id;
const botMessage = await message.author.send("Enter your registered email Id please?");
const userMessage = await MessageCollector.asyncQuestion({
botMessage,
user: message.author.id,
idle:300000 // milliseconds
}).catch(()=>{
message.author.send("Request Denied because you did not responded with a registerd email ID. You can request again!");
return 0;
});
如果有人能告诉我哪里出错了,那就太好了。
答案 0 :(得分:1)
您使用的 asyncQuestion 函数没有 time 或 idle 属性。 相反,它具有类型为 MessageCollectorOptions 的收集器选项。
所以你应该做的是使用 asyncQuestion 定义的collectorOptions并传入一个带有你的时间选项的对象,然后你的计时器应该按预期工作。
const userMessage = await MessageCollector.asyncQuestion({
botMessage,
user: message.author.id,
collectorOptions: { time: 300000 }
}).catch(() => {
// catch code here...
});