我一直试图将单行结果(在本例中为ID)存储在变量中,以便可以在其他地方使用。我有以下内容,但没有通过。
var muteid =
con.each("SELECT max(id) as id from full_track", function(err, row) {
console.log(row.id);
});
const logembed = new discord.RichEmbed()
//.setTitle("User Muted")
.setAuthor(message.author.username, message.author.avatarURL)
.setDescription(`${tomute.user.tag} has been muted for ${ms(ms(mutedtime))}`)
.addField(`**Reason:** ${mutedreason}`, `aa`)
.setFooter(`ID: ${muteid}`)
.setTimestamp()
.setColor(3447003)
答案 0 :(得分:0)
只需将代码放入您放置控制台的con.each
处理程序中即可。
var muteid, logembed = [];
con.each("SELECT max(id) as id from full_track", function(err, row) {
console.log(row.id);
muteid = row.id;
logembed[muteid] = new discord.RichEmbed()
//.setTitle("User Muted")
.setAuthor(message.author.username, message.author.avatarURL)
.setDescription(`${tomute.user.tag} has been muted for ${ms(ms(mutedtime))}`)
.addField(`**Reason:** ${mutedreason}`, `aa`)
.setFooter(`ID: ${muteid}`)
.setTimestamp()
.setColor(3447003);
});