所以我的问题是,当我尝试删除警告并在数据库中更新警告时,遇到一个非常烦人的错误。我不知道出了什么问题,但是如果我正确地编写了所有内容,那么它应该可以正常工作,但是会出现错误...我想在输入删除警告时将其从用户数据库中删除1,然后设置警告ID设为0(警告和警告ID分别存储),警告ID可以正常工作,但是删除警告计数(wn =警告号,wid =警告ID)是一个问题。我需要从中删除1,但是会引发以下错误:
(---- =因为有我的名字而被屏蔽)
Error:
throw er; // Unhandled 'error' event
^
Error: Unknown column 'NaN' in 'field list'
at Packet.asError (C:\Users\------\Desktop\Te\node_modules\mysql2\lib\packets\packet.js:712:17)
at Query.execute (C:\Users\------\Desktop\Te\node_modules\mysql2\lib\commands\command.js:28:26)
at Connection.handlePacket (C:\Users\-----\Desktop\Te\node_modules\mysql2\lib\connection.js:417:32)
at PacketParser.onPacket (C:\Users\-----\Desktop\Te\node_modules\mysql2\lib\connection.js:75:12)
at PacketParser.executeStart (C:\Users\-----\Desktop\Te\node_modules\mysql2\lib\packet_parser.js:75:16)
at Socket.<anonymous> (C:\Users\-----\Desktop\Te\node_modules\mysql2\lib\connection.js:82:25)
at Socket.emit (events.js:315:20)
at addChunk (_stream_readable.js:295:12)
at readableAddChunk (_stream_readable.js:271:9)
at Socket.Readable.push (_stream_readable.js:212:10)
Emitted 'error' event on Query instance at:
at Query.execute (C:\Users\-----\Desktop\Te\node_modules\mysql2\lib\commands\command.js:33:14)
at Connection.handlePacket (C:\Users\-----\Desktop\Te\node_modules\mysql2\lib\connection.js:417:32)
[... lines matching original stack trace ...]
at Socket.Readable.push (_stream_readable.js:212:10)
at TCP.onStreamRead (internal/stream_base_commons.js:186:23) {
code: 'ER_BAD_FIELD_ERROR',
errno: 1054,
sqlState: '42S22',
sqlMessage: "Unknown column 'NaN' in 'field list'"
}
这是我的代码: (它可能很长,但是它用于删除警告。)
if(args[1] === "remove" && message.member.roles.cache.has(rls.Adminid) || message.member.roles.cache.has(rls.SAdminid) || message.member.roles.cache.has(rls.HAid) || message.member.roles.cache.has(rls.CAdminid) || message.member.roles.cache.has(rls.oid)){
if(!message.mentions.users.first()){
message.reply("Mention a user to remove a warning from.");
return;
}
var u = message.mentions.users.first();
if(rows[0].wid === args[3]){
if(!args[2]){
message.reply("Please may you add a warning ID to it?")
return;
}
let waid = parseInt(args[2]);
con.query(`SELECT * FROM warns WHERE id = ${u.id} AND wid = ${waid}`, (err, rows) => {
if (err) throw err;
let sql;
if(rows.length < 0){
sql = `INSERT INTO wrni (id, wn) VALUES (${u.id}, '0')`;
con.query(sql);
}
sql = `UPDATE wrni SET wn = ${rows[0].wn - 1} WHERE id = ${u.id}`;
con.query(sql);
sql = `UPDATE warns SET wid = 0 WHERE wid = ${args[2]}`;
con.query(sql);
let emb = new MessageEmbed()
.setAuthor("Warning has been removed!", u.displayAvatarURL())
.addField("From user:", u.tag, true)
.addField("User's ID:", u.id, true)
.addField("Moderator:", message.author.tag)
.addField("Warn ID:", waid)
.setColor("GREEN");
let c = message.guild.channels.cache.find(c => c.id === "706906999828250734")
c.send(emb);
message.channel.send("Warning removed from " + u.tag + "! User now has: " + rows[0].wn + " warnings!");
return;
})
数据库:
SELECT * FROM wrni;
+--------------------+----+
| id | wn |
+--------------------+----+
| 342364288310312970 | 2 |
| 317644533208711169 | 0 |
+--------------------+----+
SELECT * FROM warns;
+--------------------+--------+
| id | wid |
+--------------------+--------+
| 1000 | 0 |
| 342364288310312970 | 0 |
| 317644533208711169 | 0 |
| 342364288310312970 | 0 |
| 342364288310312970 | 0 |
| 342364288310312970 | 0 |
| 342364288310312970 | 0 |
| 342364288310312970 | 991839 |
| 342364288310312970 | 0 |
| 342364288310312970 | 411735 |
+--------------------+--------+
0 = Warn removed
Random numbers = Warn remaining.
所以是的,我不知道我的代码有什么问题,但是它根本无法正常工作。我试图用许多不同的方法来修复它,但是没有一个起作用。
答案 0 :(得分:0)
哦,它只是自我修复了idk的问题,但是它确实做了,现在可以工作了。我还没有编辑任何代码。所以我不能在这里发布解决方案。