如何设置消息的持续时间示例:
if (message.content === 'test') {
message.channel.send (`he say test in 22seconds`)
}
答案 0 :(得分:0)
您正在寻找的是setTimeout()函数。
$(document).ready(function(){
$("#about").on('click', function(){
$("div#left").html("<p>This is a <span>new</span> paragraph</p>");
});
});
答案 1 :(得分:0)
嗯..问题不是很清楚,但是我想你是说,一旦用户键入命令,机器人就会说些什么,然后用户可以用test
进行回复,机器人会告诉您它持续了多长时间带您输入test
? (试一下代码,如果不是您想要的,则可以将其删除。:))
代码:
const prefix = ''; //Put whatever prefix you want in the `(prefix goes here)`
var intervals;
bot.on("message", msg => {
let args = msg.content.substring(prefix.length).split(" ");
switch (args[0]) {
case "test": // You can call the command whatever you want
let timer = 3;
msg.channel.send("Get ready").then(msg => {
intervals = setInterval(function() {
msg.edit(`Type test in the chat in **${timer--}**..`);
}, 1000);
});
setTimeout(() => {
clearInterval(intervals);
msg.channel
.send(`Type test in the chat`)
.then(() => {
const time = Date.now();
msg.channel
.awaitMessages(
function(userMsg) {
if (userMsg.content === "test") return true;
},
{
max: 1,
time: 10000,
errors: ["time"]
}
)
.then(function(collected) {
const endTime = Date.now();
let successMsg = "Congratulations!\n";
let collectedArr = Array.from(collected.values());
for (let msg of collectedArr) {
let timeDiff = (endTime - msg.createdTimestamp) / 100;
successMsg += `You took ${timeDiff} seconds to type test.\n`;
}
msg.channel.send(successMsg);
})
.catch(function(collected) {
msg.channel.send(`You did not answer in time!`);
});
})
.catch(function(err) {
console.log(err);
});
}, 5000);
break;
}
});
我不太确定您要的是什么,但希望是这样!再次尝试一下,看看是否可行。
答案 2 :(得分:0)
如果您正在寻找机器人接收消息所花费的时间,请使用:
if (message.content === 'test') {
const seconds = ((Date.now()-message.createdTimestamp)/1000).toFixed(2);
message.channel.send (`he say test in ${seconds} seconds`)
}