gpt4 book ai didi

javascript - .js + sql变量无法求和

转载 作者:行者123 更新时间:2023-12-01 00:06:23 26 4
gpt4 key购买 nike

它只是给出两个变量的总和,而不是两个变量的总和

例如。 1 + 2 = 12 而不是 1 + 2 = 3 或 args[1] + Money = args[1]money 而不是新值

const { RichEmbed } = require('discord.js');

module.exports = {

name: 'givemoney',

description: 'Gives User Money',

usage: '<username | id | mention | amount>',

run: (client, message, args, con) => {
const target = message.mentions.users.first() || message.guild.members.get(args[1]) || message.author;


if (!args[0]) {
return message.channel.send('This is args 1');
}
if (!args[1]) {
return message.channel.send('This is args 2');
}

con.query(`SELECT money FROM account WHERE id = '${target.id}'`, (err, rows) => {
if(err) throw err;


const money = rows[0].money;
parseInt(args[1].value, 10) + money;

const sql = `UPDATE account SET money = '${money}' WHERE id = '${target.id}'`;

con.query(sql);

message.channel.send(`You have given ${target} $${args[1]}, They now have $${money}`);
});

},
};

最佳答案

我看不到你在哪里执行此操作并将其分配给变量,也许你的意思是这一行parseInt(args[1].value, 10) + Money;?此行未分配给变量,但无论如何,您面临的问题似乎与字符串连接有关,而不是与数字有关,只需在变量之前添加一个 + 符号,如下所示

let args = ["1", "2", "3"];
let money = "3";
let newVal = (+args[1]) + (+money);

console.log(newVal);

关于javascript - .js + sql变量无法求和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60349973/

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