机器人重置后可以运行的Discord.js提醒命令

时间:2020-04-10 08:47:21

标签: javascript discord discord.js

我的机器人上有一个提醒命令,但是我希望它可以存储提醒,以防我的机器人重置。我不知道该怎么做。谁能帮我吗?

这是我的命令:

    const ms = require('ms');
    
    module.exports = {
        name: "remind",
        category: "fun",
        description: "Set's a reminder.",
        run: async (client, message, args) => {
    
            if (!client.lockit) client.lockit = [];
    
            let time = args[0];
            let validUnlocks = ['release', 'unlock'];
            if (!time) return message.reply('Please set an amount of time you would like your reminder to be! `!reminder [TIME][M-S-H]`').then(m => { m.delete(20000) });
            if (validUnlocks.includes(time)) {
                message.channel.overwritePermissions(message.author.id, {
                    SEND_MESSAGES: true,
                }).then(() => {
                    message.channel.send(`${message.author}**Your reminder is up!**`);
                    clearTimeout(client.lockit[message.channel.id]);
                    delete client.lockit[message.channel.id];
                }).catch(error => {
                    console.log(error);
                });
            } else {
                message.channel.overwritePermissions(message.author.id, {
                    SEND_MESSAGES: true
                }).then(() => {
                    message.channel.send(`${message.author}, I will remind you about ${args.slice(1).join(' ')} in ___${ms(ms(time), { long: true })}___.`).then(() => {    
                        client.lockit[message.channel.id] = setTimeout(() => {
                            message.channel.overwritePermissions(message.author.id, {
                                SEND_MESSAGES: true
                            }).then(message.channel.send(`${message.author}, you had asked me to remind you, here is your reminder. The title of this reminder is "${args.slice(1).join(' ')}."`)).catch(console.error);
                            delete client.lockit[message.channel.id];
                        }, ms(time));
    
                    }).catch(error => {
                        console.log(error);
                    });
                });
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

Discord僵尸程序存在于临时缓存中,这就是为什么在推送新代码时需要重新启动它们的原因。您将需要添加一个机器人可以读取/写入的数据库,以便在重新启动时存储数据(如提醒)。