How Would I Go About Implementing License Keys In My Discord.js Bot?
I came on StackOverflow today to ask this question. How would I go about implementing a serial key for my Discord bot? I want to make it so if you haven't entered your serial key,
Solution 1:
if you have a mysql database you can do something along the lines of this:
const mysql = require("mysql")
/* ------------------------------------------------- *
* On Recieved Message *
* ------------------------------------------------- */
client.on('message', async message => {
// ...var active = false;
// if server has active key alreadyDatabase.query(`select * from table where server = '${client.guilds.get(message.guild.id).id}'`, (err, rows) => {
if (err) returnconsole.log(err)
if (!rows || rows.length <= 0) {
returnDatabase.query(`Insert into table (id, active) values (${client.guilds.get(message.guild.id).id}, false)`)
}
active = rows[0].active
})
// activate keyif (message.content.startsWith('!activate')) {
// if key exists in table: keyDatabase.query(`select * from keys where key = '${message.content.split(" ")[1]}'`, (err, rows) => {
if (err) returnconsole.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 tableDatabase.query(`update server set active = 'true' where id = '${client.guilds.get(message.guild.id).id}'`, (err, rows) => {
if (err) returnconsole.log(err)
active = true;
Database.query(`Delete from keys where key = '${key}'`)
})
}
})
}
// if server has active key let them continue else return themif (!active == 'true') return;
// Command handler;
});
as for generating the key, ill leave that up to you. (have a look at uuid generators if you have no clue.)
Post a Comment for "How Would I Go About Implementing License Keys In My Discord.js Bot?"