Using the WOK Thanks Command code that I cloned from the repo, and edited a bit, but I get the ReferenceError: Invalid left-hand side in assignment
from commando in discord itself when I type out the command.
Code:
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)
}
}
Here's the schema:
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)
The code does not return any errors in the console itself, just discord, and the bot keeps running as if nothing happened, but the command doesn't work because the process is stopped. I couldn't find any apparent problems with operators, which is what I was expecting to have from this error...
The error is not from Discord.JS or Commando, it's from this line in your run()
function
const diff = now.getTime() = then.getTime()
Did you mean this?
const diff = now.getTime() - then.getTime()
When an error is thrown, look for the file path and line where the error emits