这是我用来做狙击的狙击代码,但它不会烦人地工作
module.exports = {
name: 'snipe',
description: 'Shows the last deleted message',
async execute(client, message, cmd, args, Discord) {
try{
const msg = client.snipes.get(message.channel.id)
const embed = new Discord.MessageEmbed()
.setTitle('Sniped')
.setDescription(msg.content)
.setColor('GREEN')
.setTimestamp()
message.channel.send(embed).catch(err => console.error(err));
}catch(e){
console.log(e)
}
}
}
这是我的消息删除事件,我知道它没有出现任何错误,但如果您发现需要在其中包含任何内容,请告诉我,我会将其放入。
module.exports = async (Discord, client, message) => {
try{
if(message.author.bot) return;
client.snipes.set(message.channel.id, {
content: message.content,
author: message.author.tag,
member: message.member,
image: message.attachments.first() ? message.attachments.first().proxyURL : null
})
}catch(e){
console.log(e)
}
}
这是我一直犯的错误。
TypeError: Cannot read property 'content' of undefined
at Object.execute (C:\Users\\Desktop\Discordproject\commands\Utilities\snipe.js:10:21)
at module.exports (C:\Users\\Desktop\Discordproject\events\guild\message.js:13:25)
at Client.emit (node:events:394:28)
at MessageCreateAction.handle (C:\Users\\Desktop\Discordproject\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\\Desktop\Discordproject\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\\Desktop\Discordproject\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (C:\Users\\Desktop\Discordproject\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Users\\Desktop\Discordproject\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Users\[\Desktop\Discordproject\node_modules\ws\lib\event-target.js:132:16)
at WebSocket.emit (node:events:394:28)
at Receiver.receiverOnMessage (C:\Users\Desktop\Discordproject\node_modules\ws\lib\websocket.js:834:20)
at Receiver.emit (node:events:394:28)
at Receiver.dataMessage (C:\Users
\Desktop\Discordproject\node_modules\ws\lib\receiver.js:437:14)
at Receiver.getData (C:\Users
\Desktop\Discordproject\node_modules\ws\lib\receiver.js:367:17)
at Receiver.startLoop (C:\Users
\Desktop\Discordproject\node_modules\ws\lib\receiver.js:143:22)
at Receiver._write
(C:\Users\Desktop\Discordproject\node_modules\ws\lib\receiver.js:78:10)
就像我说的,我不知道过去 3 个小时我一直在尝试的问题是什么,但仍然无法弄清楚问题是什么。