Discord JS V12 使用命令启用和禁用事件

DiscordJS V12 Enabling & Disabling Events With A Command

我想创建一个命令来启用或禁用 [​​=11=] 并且会自动禁用我该怎么做?

事件:

    return message.channel.send(new Discord.MessageEmbed()
      .setColor(ee.wrongcolor)
      .setFooter(ee.footertext, ee.footericon)
      .setTitle(`❌ Unkown command, try: **\`${prefix}help\`**`)
      .setDescription(`.setup has a list of info you might need`)
    ).then(msg=>msg.delete({timeout: 5000}).catch(e=>console.log("Couldn't Delete".gray)));

您必须能够将变量保存在某处(数据库、json 文件等)。我更喜欢数据库,但这是我个人的偏好。所以我的答案将基于将其保存到数据库中。这可能不是您的选择,但它可以工作。

const con = require('./database.js')

// if doing it as a message command with a prefix

client.on('messageCreate', async message => {
// set up command recognition here

    if (command === 'enable-event') {
        con.query(`UPDATE database_name SET event = 'enabled' WHERE event_name = 'invalid'`)
    } else if (command === 'disable-event') {
        con.query(`UPDATE database_name SET event = 'disabled' WHERE event_name = 'invalid'`)
    }

    if (!command) {
        con.query(`SELECT * FROM database_name WHERE event_name = 'invalid'`, (err, rows) => {
            if (err) throw err
            const status = rows[0].event

            if (status === 'enabled') {
                const embed = new Discord.MessageEmbed()
                    .setColor(ee.wrongcolor)
                    .setFooter(ee.footertext, ee.footericon)
                    .setTitle(`❌ Unkown command, try: **\`${prefix}help\`**`)
                    .setDescription(`.setup has a list of info you might need`)

                return message.channel.send({
                    embeds: [embed]
                }).then((msg) => {
                      msg.delete({
                          timeout: 5000
                      })
                  }).catch(e => 
                        console.log("Couldn't Delete".gray)
                    )
            } else {
            return
            }
        })
    }
})