【问题标题】:I get error by making snipe command that shows the latest deleted message我通过发出显示最新删除消息的狙击命令得到错误
【发布时间】:2020-04-22 02:04:32
【问题描述】:

我正在尝试在您键入时发出命令,例如 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);
    }
} 

教程中的那个人没有说明他是如何得到那个狙击手的。所以它对我不起作用。 我不知道还要在那里添加什么,所以基本上我处于死胡同。

【问题讨论】:

  • 它告诉你client.snipes 是未定义的。它不是客户端对象的标准部分。你创造了这个吗?如果是,你确定那部分代码被执行了吗?
  • 我没有创建这个.. 是的,正如我所说,没有 client.snipes 之类的东西.. 这家伙没有展示他是如何做到的.. 所以他实际上展示了一个最终在死胡同..我不知道在这个客户端中添加什么.snipes..我不知道该怎么做..

标签: discord discord.js


【解决方案1】:

您是否为狙击手定义了Map() Discord#Collection(扩展 Map() 的类)?您尝试获取的频道 ID 应该是上述 Map 的键

【讨论】:

    【解决方案2】:

    这是为您的客户制作.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); 
    }
    

    【讨论】:

      猜你喜欢
      • 2019-03-01
      • 1970-01-01
      • 2020-11-23
      • 1970-01-01
      • 2021-04-21
      • 2021-01-30
      • 2021-02-27
      • 2021-07-29
      • 2021-04-25
      相关资源
      最近更新 更多