i just started programming one bot for my discord, i'm facing an issue with him, i will try be specific as possible.
so i have mysql database which contains my game data, and i want to use that table so my players are able to authenticate by them self's and unlock the panel which is locked.
the table is users, and i created column discordId, and what i want to make, is when the player run the command it needs to execute SELECT * FROM users WHERE discordId = '${target.id}'
, id there is not record in discordId , then try UPDATE users SET discordId = '${message.author.id}' WHERE name = '${message.author.username}'
, but probably the player doesn't have the same name in discord as on the game, so i want throw him a message to change his game name to the same name as discord.
i will show you my .js file
const { MessageEmbed } = require("discord.js")
const { redlight } = require("../../colours.json");
module.exports = {
config: {
name: "auth",
description: "Authentication to the Billing with discord!",
usage: "%auth",
category: "panel",
accessableby: "Members",
aliases: ["authentication", "access"]
},
run: async (bot, message, args, con) => {
let target = message.author;
con.query(`SELECT * FROM users WHERE discordId = '${target.id}'`, (err, req) => {
if(err) throw err;
if(!req[0].discordId) return message.channel.send(`**${message.author.username}** Please change your lord name in game to **${message.author.username}** and then do %auth`)
message.delete();
if(err) throw err;
con.query(`UPDATE users SET discordId = '${message.author.id}' WHERE name = '${message.author.username}'`);
message.channel.send(`You have been authenticated **${message.author.username}**...`);
if(message.mentions.users.first()) return message.channel.send("You're not allowed to do that!");
// return;
let embed = new MessageEmbed()
.setColor(redlight)
.setAuthor(`${message.guild.name} Modlogs`, message.guild.iconURL)
.addField("Panel:", "Authentication")
.addField("Player:", message.author.username)
.addField("Description:", "Have been authenticated")
.addField("Date:", message.createdAt.toLocaleString())
let sChannel = message.guild.channels.cache.find(c => c.id === "801181624809160735")
sChannel.send(embed);
});
}
}
i really need help here please, don't forget i'm just starting kearning how to do discord bot's.
TIA.
question from:
https://stackoverflow.com/questions/65830884/discord-js-with-mysql-query-and-if-not-send-message-to-channel 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…