簡體   English   中英

我試圖運行命令 Discord.js 但出現錯誤“TypeError:無法讀取未定義的屬性'get'”

[英]i m trying to run a command Discord.js but error appear “TypeError: Cannot read property 'get' of undefined”

下面有一個代碼希望有人幫助我:) 我試圖在谷歌上搜索但沒有找到任何解決方案

const { MessageEmbed } = require("discord.js");

  module.exports.run = async (bot, message, args) => {
    const snipes = bot.snipes.get(message.channel.id) || [];
    const msg = snipes[args[0] - 1 || 0];
    if (!msg) return message.channel.send(`That is not a valid snipe...`);
    const Embed = new MessageEmbed()
      .setAuthor(
        msg.author.tag,
        msg.author.displayAvatarURL({ dynamic: true, size: 256 })
      )
      .setDescription(msg.content)
      .setFooter(`Date: ${msg.date} | ${args[0] || 1}/${snipes.length}`);
    if (msg.attachment) Embed.setImage(msg.attachment);
    message.channel.send(Embed);
  },
  module.exports.help = {
    name: "snipe",
    
}

附上錯誤的位置是正常的(通常以error: 53,23的形式,以便用戶更容易找到它。

首先,未定義的錯誤是最常見的錯誤( 請閱讀)。 它們發生在您沒有聲明變量或您使用的方法不正確時。 在這種情況下,我相信它來自這條線:

const snipes = bot.snipes.get(message.channel.id) || [];

我不知道snipes是什么,但在 v12 中我們使用cache ,並且#get已不再使用( 另請閱讀

如果我知道什么是狙擊手,我可以告訴你正確的代碼是什么,但我不知道。 請使用隨附的信息來查看是否可以解決問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM