我正在尝试让Discord机器人在10秒后删除其“系统消息”,因为我看到了很多“无效命令”错误和“完成!”通知,我希望清除它们以便查看实际消息。这与删除用户具有命令的消息不同;我已经具备了这种能力。
message.reply('Invalid command')
.then(msg => {
setTimeout(() => msg.delete(), 10000)
})
.catch(/*Your Error handling if the Message isn't returned, sent, etc.*/);
Message.delete()
函数的更多信息,以及Node文档以获取有关setTimeout()
的信息。message.reply('Invalid command')
.then(msg => {
msg.delete({ timeout: 10000 })
})
.catch(/*Your Error handling if the Message isn't returned, sent, etc.*/);
Discord.JS v11:
message.reply('Invalid command')
.then(msg => {
msg.delete(10000)
})
.catch(/*Your Error handling if the Message isn't returned, sent, etc.*/);
msg.delete(10000)
更改为msg.delete({ timeout: 10000 })
。 - TonysetTimeout(() => msg.delete(), 10000)
。 - PiggyPlex当前API与早期版本不同。现在传递超时的正确方法如下。
Discord.js v13
message.reply('Invalid command!')
.then(msg => {
setTimeout(() => msg.delete(), 10000)
})
.catch(console.error);
Discord.js v12
->Discord.js版本12
message.reply('Invalid command!')
.then(msg => {
msg.delete({ timeout: 10000 })
})
.catch(console.error);
每个Discord.JS版本都有一种新的超时删除方式。
Discord.JS V11:
每个Discord.JS版本都有自己的超时删除方式。message.channel.send('Test!').then(msg => msg.delete(10000));
Discord.JS V12:
message.channel.send('Test!').then(msg => msg.delete({timeout: 10000}));
Discord.JS V13:
message.channel.send('Test!').then(msg => setTimeout(() => msg.delete(), 10000));
时间以毫秒为单位计算