gpt4 book ai didi

mysql - Node.js 在连接到 mysql 数据库后崩溃

转载 作者:行者123 更新时间:2023-11-30 21:30:12 25 4
gpt4 key购买 nike

基本上,node.js 会完美地运行该函数,它会继续运行约 10 秒,然后就会崩溃。下面是完整的代码,因为我不知道是哪一部分导致了实际的错误,但我希望有人能看到我哪里搞砸了。

const Discord = require("discord.js");
const client = new Discord.Client();
const config = require("./config.json");
var fs = require('fs');
var mysql = require('mysql');
const path = require('path');

client.on("ready", () => {
console.log('Running...');
});

var con = mysql.createConnection({
host: "",
user: "",
password: "",
database: "",
});

client.on("message", async message => {
if (message.author.bot) return;
if (!message.guild) {
message.reply('Please do not DM the bot.');
return;
};
if (message.content.toLowerCase() == "!script") {
if (message.channel.name != "bot-chat") {
message.author.send('Please only use bot commands in the #bot-chat channel.');
return;
};
con.connect(function(err) {
if (err) throw err;
con.query("SELECT * FROM Users", function (err, result, fields){
if (err) throw err;
result.forEach(function(User){
var UserDiscord = User.DISCORD;
var UserKey = User.SKEY;
if (usr_dc == message.author.username+"#"+message.author.discriminator) {
message.author.sendCode("php",usr_key)
.then()
.catch(console.log);
if (message.guild.name == "Towlie Boi") {
message.author.sendCode("lua",`_G.key='KeyHere'
loadstring(game:HttpGet("https://basehosting.xyz/sCrIpT1"))()`)
.then()
.catch(console.log);
message.channel.send('Script has been sent to your DMs, If you did not receive a DM then you have not allowed the bot to send you DMs');
.then()
.catch(console.log);
};
};
});
});
});
} else if (message.channel.name == 'whitelist') {
if (message.content.substring(0,3).toLowerCase() == '!wl') {
con.connect(function(err) {
if (err) throw err;
con.query("SELECT * FROM Keys", function(err, result, fields) {
if (err) throw err;
result.forEach(function(Key) {
var key = Key.Code;
if (message.content.substring(4) == key) {
var query = "DELETE FROM `Keys` WHERE `Keys`.`Code` = \'"+message.content.substring(4)+"\'";
con.query(query, function(err) {
if (err) throw err;
con.query("INSERT INTO `Users` (`DISCORD`, `SKEY`, `IP`) VALUES ('"+message.author.username+"#"+message.author.discriminator+"', '"+message.content.substring(4)+"', '');", function(err) {
if (err) throw err;
message.reply('Whitelisted Succesfully');
return;
});
});
};
});
});
});
};
};
};

client.login(config.token);

我真的看不出错误,因为我刚刚开始为 node.js 编码并且对 javascript 了解不多,我想我可能必须在排队数据后关闭连接,但这似乎也没有用.感谢您的任何回答:)

最佳答案

如何从单独的文件连接数据库。

module.exports = {
host : 'localhost',
user : 'root',
password : '',
database : 'bookstore',
charset : 'utf8'
}

并继续控制。

var database = require('../models/database.js')();

关于mysql - Node.js 在连接到 mysql 数据库后崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56678360/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com