gpt4 book ai didi

node.js - 值与 bot 和 mysql 数据库的通讯不正确

转载 作者:太空宇宙 更新时间:2023-11-04 01:41:07 25 4
gpt4 key购买 nike

所以我正在研究一个允许你花费积分来升级的命令。这些点存储在一个名为“点”的表中,与数据库中的相同。每行包含用户的不和谐雪花 ID 以及他们有多少积分。

当你运行例如 !rankup 时的期望:检查你的级别(现在每个人都是 0,然后从数据库中减去 100 点(如果有的话)并为你分配级别 1 的新角色。

结果:积分没有被减去,并且抛出此错误:

    (node:10784) DeprecationWarning: Collection#find: pass a function instead
(node:10784) UnhandledPromiseRejectionWarning: Error: Value must be specified.
at Map.find (C:\github\discordBot\node_modules\discord.js\src\util\Collection.js:499:45)
at Object.module.exports.run (C:\github\discordBot\cmds\rankup.js:12:29)
at Client.bot.on (C:\github\discordBot\index.js:77:17)
at Client.emit (events.js:182:13)
at MessageCreateHandler.handle (C:\github\discordBot\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
at WebSocketPacketManager.handle (C:\github\discordBot\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:103:65)
at WebSocketConnection.onPacket (C:\github\discordBot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (C:\github\discordBot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
at WebSocket.onMessage (C:\github\discordBot\node_modules\ws\lib\event-target.js:120:16)
at WebSocket.emit (events.js:182:13)
(node:10784) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:10784) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
null OkPacket {
fieldCount: 0,
affectedRows: 1,
insertId: 0,
serverStatus: 34,
warningCount: 0,
message: '(Rows matched: 1 Changed: 1 Warnings: 0',
protocol41: true,
changedRows: 1 } undefined

这是整个命令的代码:

    const Discord = module.require("discord.js");
module.exports.run = async (bot, message, args) => {


let toPromote = message.author;

if(message.member.roles.find("Level 0")){ //level 0
con.query(`SELECT * FROM points WHERE id = '${toPromote.id}'`, (err, rows) =>{ //get points from database
if(err) throw err;

let sql;

if(rows.length > 1) { //Has points
//previous points found
let points = rows[0].points;
if(points > 100){ //has more than 100 points
sql = `UPDATE points SET points = ${points - 100} WHERE id = '${toPromote.id}'`; //subtract 100 points
toPromote.removeRole(level0); //change their roles
toPromote.addRole(level1); //change their roles
}


}
con.query(sql, console.log);
});


}else if(message.member.roles.find("Level 2")){ //level 1

}else if(message.member.roles.find("Level 3")){ //level 2

}else if(message.member.roles.find("Level 4")){ //level 3

}else if(message.member.roles.find("Level 5")){ //level 4

}else{ //no level role, assign them one(make it if it doesn't exist)


if(!level0) {
try{
role = await message.guild.createRole({
name: "Level 0",
color: "#000000",
permission: []
});
} catch(e) {
console.log(e.stack);
}
}

toPromote.addRole(level0);
}
};
module.exports.help = {
name: "rankup"
}

最佳答案

根据Roles and Permissions你应该检查这样的权限:

if(message.member.roles.has(role.id)) {

}

您将一个字符串传递到 .find 方法中,抛出的错误还告诉您应该将一个函数传递到该方法中。但 .has 函数应该用于检查用户角色。

关于node.js - 值与 bot 和 mysql 数据库的通讯不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52909742/

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