使用我从 repo 克隆的 WOK Thanks Command 代码,并进行了一些编辑,但是ReferenceError: Invalid left-hand side in assignment
当我输入命令时,我从不和谐中获得了来自 commando 的代码。
代码:
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)
该代码不会在控制台本身返回任何错误,只是不和谐,并且机器人继续运行,就好像什么都没发生一样,但是该命令不起作用,因为进程已停止。我找不到操作员的任何明显问题,这是我期望从这个错误中得到的......