【问题标题】:ReferenceError: Cannot access 'embed' before initializationReferenceError:在初始化之前无法访问“嵌入”
【发布时间】:2020-09-17 05:30:49
【问题描述】:

这是我的代码,但我不知道应该把“const embed = new Discord.RichEmbed()”这一行放在哪里。

    const Discord = require("discord.js");

module.exports = {
  name: "events",
  description: "Display the events!",
  execute(message, bot, args){
    message.channel.sendEmbed(embed);
  const embed = new Discord.RichEmbed()
  .setTitle("Event Times")
  .setDescription("Server's timezone: UTC+3")
  .setThumbnail("https://i.imgur.com/Jk5Wxj3.png")
  .addFields(
      { name: '\u200B', value: '\u200B' },
      { name: 'Monday', value: 'DemaNeR - Start 8AM' }, // Value is the event name and time.
      { name: 'Tuesday', value: 'Spaceball - Start 6PM' }, // value: 'new value'
      { name: 'Wednesday', value: 'JPB- Start 10PM' },
      { name: 'Thursday', value: 'Invasion - Start 9PM' },
      { name: 'Friday', value: 'Hitac - Start 4PM' },
      { name: 'Saturday', value: 'CVC(Infiltration) - All Day' },
      { name: 'Sunday', value: 'JPB - Start 7PM ->> Invasion - Start 10PM' },
  )
  .setColor("#f36639")

}

  }

【问题讨论】:

  • 如果高于module.exports,您可以输入
  • 如果你缩进得当,你会发现你的代码更容易调试。

标签: javascript discord discord.js


【解决方案1】:

您在定义之前引用了embed

execute(message, bot, args) {
    const embed = new Discord.RichEmbed()
        /* code omitted for brevity */       
    message.channel.sendEmbed(embed);
}

【讨论】:

  • 谢谢。解决了!
  • @W3X 的常见礼貌是也支持正确答案
【解决方案2】:

只需切换这两行

   message.channel.sendEmbed(embed);
  const embed = new Discord.RichEmbed()

成为

   const embed = new Discord.RichEmbed();
   message.channel.sendEmbed(embed);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-29
    • 2021-09-10
    • 2020-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多