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"
}
解决方案
一种简单的方法是使用一个简单的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
}
推荐阅读
- node.js - 尝试要求文件夹模块时抛出错误?
- javascript - 从 props 向卡片组件添加背景图片
- php - 是否可以将 CLI 命令 (exec) 的输出捕获到 PHP 脚本变量?
- c# - 使用具有不同分辨率的不同显示器时,自定义为在 winforms 中切换按钮的复选框无法正确呈现
- javascript - Mongoose ValidationError:验证失败:需要路径
- python - tkinter - 我需要删除最小化按钮,而不是禁用,并更改所有栏的颜色
- node.js - Sequelize 5:多对多方法上的 TypeError
- testing - Spring Boot TestContainers 映射的端口只能在容器启动后获取
- python - Flask - 将按钮直接指向另一个页面
- javascript - 使用Javascript拖放非常慢