我该如何在我的Discord.js机器人中实现许可证密钥呢? [英] How would I go about implementing license keys in my Discord.js bot?

查看:0
本文介绍了我该如何在我的Discord.js机器人中实现许可证密钥呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天来StackOverflow问这个问题。我该如何为我的不和谐机器人实现一个序列密钥呢?我想这样做,如果您没有输入您的序列密钥,那么所有命令都不会起作用。我不希望序列密钥被重复使用,或在其他行会中使用。我现在有点困惑,有没有人能帮帮我,指出我应该怎么做?

推荐答案

如果您有一个MySQL数据库,您可以这样做:

const mysql = require("mysql")

/* ------------------------------------------------- *
 *             On Recieved Message                   *
 * ------------------------------------------------- */
client.on('message', async message => {
    // ...

    var active = false;

    // if server has active key already
    Database.query(`select * from table where server = '${client.guilds.get(message.guild.id).id}'`, (err, rows) => {
        if (err) return console.log(err)
        if (!rows || rows.length <= 0) {
            return Database.query(`Insert into table (id, active) values (${client.guilds.get(message.guild.id).id}, false)`)
        }

        active = rows[0].active
    })

    // activate key
    if (message.content.startsWith('!activate')) {

        // if key exists in table: key
        Database.query(`select * from keys where key = '${message.content.split(" ")[1]}'`, (err, rows) => {
            if (err) return console.log(err)
            if (!rows || rows.lenght <= 0) {
                return message.channel.send('Invalid code')
            } else {
                let key = rows[0].key
                    // if key exists remove and update server table
                Database.query(`update server set active = 'true' where id = '${client.guilds.get(message.guild.id).id}'`, (err, rows) => {
                    if (err) return console.log(err)
                    active = true;

                    Database.query(`Delete from keys where key = '${key}'`)

                })
            }
        })
    }

    // if server has active key let them continue else return them
    if (!active == 'true') return;
    // Command handler;

});
至于生成密钥,我将由您决定。(如果您一无所知,请查看UUID生成器。)


这篇关于我该如何在我的Discord.js机器人中实现许可证密钥呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆