我通过执行显示最新删除消息的狙击命令而出错

时间:2020-04-21 14:51:45

标签: discord discord.js

我试图在您键入例如z!snipe的地方发出命令 它显示了最后一条删除的消息,作者在顶部,消息在中间。 但这不起作用。 youtube上关于如何执行此操作的教程并不多。

我设法找到了一个,但是没有用。问题是: TypeError: Cannot read property 'get' of undefined

我的代码是:

const { Discord, RichEmbed } = require("discord.js");

module.exports ={
    name: "snipe",
    category: "info",
    description: "Shows the most recent deleted message.",
    usage: "z!snipe",
    run: async(client, message, args) => {
        const msg = client.snipes.get(message.channel.id);
        if(!msg) return message.reply("There are no recently deleted messages!");

        const embed = new RichEmbed()
            .setAuthor(`Deleted by ${msg.author.tag}`, msg.author.displayAvatarURL())
            .setDescription(msg.content);
    }
} 

本教程中的那个家伙没有显示他是如何获得该狙击手的东西的,所以对我不起作用。 我不知道要在此添加什么,所以基本上我处于死胡同。

2 个答案:

答案 0 :(得分:0)

这是为客户制作.snipes的简单方法。它实际上只是将每个已删除的味精存储到其通道ID。您可以添加更多功能,但这足以回答您的问题:D

client.snipes = function(){
   get(ChannelId){
       return this[ChannelId];
   }
   set(msg){
      this[msg.channel.id] = msg;
   }
}
client.on('messageDelete',function(msg){
   client.snipes.set(msg); 
}

答案 1 :(得分:0)

您是否为片段定义了Map() Discord#Collection(扩展Map()的类)?您尝试获取的频道ID应该是Map

的键