ReferenceError: Invalid left-hand side in assignment in discord.js commando
ReferenceError: Invalid left-hand side in assignment in discord.js commando
使用我从 repo 克隆的 WOK Thanks 命令代码,并进行了一些编辑,但是当我输入命令时,我从 commando in discord 本身得到了 ReferenceError: Invalid left-hand side in assignment
。
代码:
const Commando = require('discord.js-commando')
const Discord = require('discord.js')
const thanksSchema = require('@schemas/thanks-schema')
module.exports = class ThanksCommand extends Commando.Command {
constructor(client) {
super(client, {
name: 'thanks',
group: 'thanks',
memberName: 'thanks',
description: 'Thanks a staff member for their help',
})
}
async run(message) {
const target = message.mentions.users.first()
if (!target) {
const noPingThanksEmbed = new Discord.MessageEmbed()
.setTitle('ERROR: Invalid user provided')
.setDescription('Please tag a valid user')
.setColor('#ff0000')
message.channel.send(noPingThanksEmbed)
return
}
const { guild } = message
const guildId = guild.id
const targetId = target.id
const authorId = message.author.id
const now = new Date()
if (targetId === authorId) {
const thankSelfEmbed = new Discord.MessageEmbed()
.setTitle('ERROR: Invalid user provided')
.setDescription('You cannot thank yourself')
.setFooter('LOL YOU THOUGHT')
.setColor('#ff0000')
message.channel.send(thankSelfEmbed)
return
}
const authorData = await thanksSchema.findOne({
userId: authorId,
guildId,
})
if (authorData && authorData.lastGave) {
const then = new Date(authorData.lastGave)
const diff = now.getTime() = then.getTime()
const diffHours = Math.round(diff / (1000 * 60 * 60))
const hours = 24
if (diffHours <= hours) {
const cooldownThankEmbed = new Discord.MessageEmbed()
.setTitle('ERROR: User on cooldown')
.setDescription(`You have already thanked someone within the last ${hours} hours`)
.setColor('#ff0000')
message.channel.send(cooldownThankEmbed)
return
}
}
await thanksSchema.findOneAndUpdate({
userId: authorId,
guildId,
}, {
userId: authorId,
guildId,
lastGave: now,
}, {
upsert: true,
})
const result = await thanksSchema.findOneAndUpdate({
userId: targetId,
guildId,
}, {
userId: targetId,
guildId,
$inc: {
received: 1,
}
}, {
upsert: true,
new: true,
})
const amount = result.received
const thanksEmbed = new Discord.MessageEmbed()
.setTitle('SUCCESS')
.setDescription(`<@${authorId}> has thanked <@${targetId}!\n\nThey now have ${amount} thanks`)
.setColor('#1be730')
message.channel.send(thanksEmbed)
}
}
架构如下:
const mongoose = require('mongoose')
const reqString = {
type: String,
required: true,
}
const thanksSchema = mongoose.Schema({
userId: reqString,
guildId: reqString,
received: {
type: Number,
default: 0
},
lastGave: Date
})
module.exports = mongoose.model('thanks', thanksSchema)
代码在控制台本身 return 没有任何错误,只是不和谐,机器人保持 运行 好像什么都没发生一样,但是命令不起作用,因为进程已停止.我找不到任何明显的运算符问题,这是我期望从这个错误中得到的...
错误不是来自 Discord.JS 或 Commando,而是来自 run()
函数中的这一行
const diff = now.getTime() = then.getTime()
你是这个意思吗?
const diff = now.getTime() - then.getTime()
当抛出错误时,查找错误发出的文件路径和行
使用我从 repo 克隆的 WOK Thanks 命令代码,并进行了一些编辑,但是当我输入命令时,我从 commando in discord 本身得到了 ReferenceError: Invalid left-hand side in assignment
。
代码:
const Commando = require('discord.js-commando')
const Discord = require('discord.js')
const thanksSchema = require('@schemas/thanks-schema')
module.exports = class ThanksCommand extends Commando.Command {
constructor(client) {
super(client, {
name: 'thanks',
group: 'thanks',
memberName: 'thanks',
description: 'Thanks a staff member for their help',
})
}
async run(message) {
const target = message.mentions.users.first()
if (!target) {
const noPingThanksEmbed = new Discord.MessageEmbed()
.setTitle('ERROR: Invalid user provided')
.setDescription('Please tag a valid user')
.setColor('#ff0000')
message.channel.send(noPingThanksEmbed)
return
}
const { guild } = message
const guildId = guild.id
const targetId = target.id
const authorId = message.author.id
const now = new Date()
if (targetId === authorId) {
const thankSelfEmbed = new Discord.MessageEmbed()
.setTitle('ERROR: Invalid user provided')
.setDescription('You cannot thank yourself')
.setFooter('LOL YOU THOUGHT')
.setColor('#ff0000')
message.channel.send(thankSelfEmbed)
return
}
const authorData = await thanksSchema.findOne({
userId: authorId,
guildId,
})
if (authorData && authorData.lastGave) {
const then = new Date(authorData.lastGave)
const diff = now.getTime() = then.getTime()
const diffHours = Math.round(diff / (1000 * 60 * 60))
const hours = 24
if (diffHours <= hours) {
const cooldownThankEmbed = new Discord.MessageEmbed()
.setTitle('ERROR: User on cooldown')
.setDescription(`You have already thanked someone within the last ${hours} hours`)
.setColor('#ff0000')
message.channel.send(cooldownThankEmbed)
return
}
}
await thanksSchema.findOneAndUpdate({
userId: authorId,
guildId,
}, {
userId: authorId,
guildId,
lastGave: now,
}, {
upsert: true,
})
const result = await thanksSchema.findOneAndUpdate({
userId: targetId,
guildId,
}, {
userId: targetId,
guildId,
$inc: {
received: 1,
}
}, {
upsert: true,
new: true,
})
const amount = result.received
const thanksEmbed = new Discord.MessageEmbed()
.setTitle('SUCCESS')
.setDescription(`<@${authorId}> has thanked <@${targetId}!\n\nThey now have ${amount} thanks`)
.setColor('#1be730')
message.channel.send(thanksEmbed)
}
}
架构如下:
const mongoose = require('mongoose')
const reqString = {
type: String,
required: true,
}
const thanksSchema = mongoose.Schema({
userId: reqString,
guildId: reqString,
received: {
type: Number,
default: 0
},
lastGave: Date
})
module.exports = mongoose.model('thanks', thanksSchema)
代码在控制台本身 return 没有任何错误,只是不和谐,机器人保持 运行 好像什么都没发生一样,但是命令不起作用,因为进程已停止.我找不到任何明显的运算符问题,这是我期望从这个错误中得到的...
错误不是来自 Discord.JS 或 Commando,而是来自 run()
函数中的这一行
const diff = now.getTime() = then.getTime()
你是这个意思吗?
const diff = now.getTime() - then.getTime()
当抛出错误时,查找错误发出的文件路径和行