延迟删除事件

时间:2019-01-22 02:52:49

标签: discord.js

我的discord.js机器人上有一个票务系统,当您关闭它时,它会立即关闭。我很好奇是否有办法将其删除延迟1小时。这是我的代码:

const Discord = require('discord.js');

module.exports.run = async (bot, message, args) => {
    if (!message.channel.name.startsWith('ticket')) return message.channel.send('You are not in a ticket channel!');
    let reason = args[0] | 'Ticket Closed!'
    message.channel.delete(args[0])
}

module.exports.help = {
  name: "close"
}

2 个答案:

答案 0 :(得分:3)

一种简单的方法是使用简单的setTimeout函数。例如:

module.exports.run = async (bot, message, args) => {
    if (!message.channel.name.startsWith('ticket')) return message.channel.send('You are not in a ticket channel!');
    let reason = args[0] | 'Ticket Closed!'

    setTimeout(() => {
        message.channel.delete(args[0]);
    }, 60 * 60 * 1000); // Sets timeout for 1 hour
}

答案 1 :(得分:0)

您可以使用

.then(m => m.delete(time in ms));
消息后的

。 或者,如果要在删除之前对其进行编辑:

const msg = await message.channel.send("Edit message!")
msg.edit("It's edited now!")
msg.edit("You can do it multiple times!")
// You can use a setTimeout() here if you want a delay. Also, make sure that this is in an async function
msg.delete()
相关问题