Hello, I wish to create a discord bot that users can use a simple command to input the username and password, then delete the typed message.
Need help finishing this, trying to make a Discord bot register an account on mySQL server.
//Discord Bot
const Discord = require(‘discord.js’);
const client = new Discord.Client();
//default prefix
let prefix = “??”;
//sql
const mysql = require(‘mysql’);
var con = connection = mysql.createConnection
({
host : ‘localhost’,
port : ‘3306’,
user : ‘root’,
password : ‘’,
database : ‘auth’,
charset : ‘utf8mb4’
});
//confirm connection
con.connect(err =>
{
if(err) throw err;
console.log(“Connected to the DB.”)
})
//Bot Token
client.login(‘!TOKEN!’);
client.on(‘Ready’, readyDiscord);
//verification Bot is working
function readyDiscord() {
console.log(‘Ready!’);
}
//message function
client.on(“message”, (message) =>
{
if (!message.content.startsWith(prefix) || message.author.bot) return;
if (message.channel.id ==‘!IDCHANNEL!’ && message.content.startsWith(prefix + ‘Register’))
{
sql = “INSERT INTO account (username, verifier) VALUES (‘’, ‘’)”;
con.query(sql, function (err, result) {
if (err) throw err;
console.log(“1 record inserted”);
});
message.reply('You are registered, welcome to the server!.');
} else
//PING to confirm this works, will remove later.
if (message.channel.id =='!IDCHANNEL' && message.content.startsWith(prefix + 'Ping'))
{
message.channel.send("Pong!");
}
});
as you can see i am having trouble with the variables needed to complete this.
(Yes I don't mind sharing my code. :) )
I am hoping this can become to an actual Opensource project.