ReferenceError:discord.js 突击队中分配的左侧无效
Posted
技术标签:
【中文标题】ReferenceError:discord.js 突击队中分配的左侧无效【英文标题】:ReferenceError: Invalid left-hand side in assignment in discord.js commando 【发布时间】:2021-11-04 16:01:47 【问题描述】:使用我从 repo 克隆的 WOK Thanks Command 代码,并进行了一些编辑,但是当我输入命令时,我从不和谐的 commando 中获得了 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)
代码在控制台本身没有返回任何错误,只是不和谐,机器人继续运行,好像什么都没发生一样,但是命令不起作用,因为进程停止了。我没有发现运营商有任何明显的问题,这是我期望从这个错误中得到的......
【问题讨论】:
【参考方案1】:错误不是来自 Discord.JS 或 Commando,而是来自 run()
函数中的这一行
const diff = now.getTime() = then.getTime()
你是这个意思吗?
const diff = now.getTime() - then.getTime()
当抛出错误时,查找错误发出的文件路径和行
【讨论】:
Commando 我的意思是错误是在 Discord 本身中发送的,因此它没有给出文件路径和行。我想我打错了那行,所以谢谢你,那确实是错误。以上是关于ReferenceError:discord.js 突击队中分配的左侧无效的主要内容,如果未能解决你的问题,请参考以下文章
Discord.JS ReferenceError:未定义 stopTyping
Discord.js ReferenceError:未定义消息
为啥我收到 ReferenceError:AbortController 未在 Discord.js v13 中定义?
为啥我收到 ReferenceError:AbortController 未在 Discord.js v13 中定义?