【问题标题】:ReferenceError: message is not defined - Welcome Message - embedReferenceError:消息未定义 - 欢迎消息 - 嵌入
【发布时间】:2018-11-07 03:11:03
【问题描述】:

所以我正在玩我的欢迎信息并想将其嵌入,我最终重新编写了所有内容以使用嵌入,但是在我完成后,我收到了错误message is not defined

var welcomePath = './Storage/welcome.json';
var welcomeRead = fs.readFileSync(welcomePath);
var welcomeFile = JSON.parse(welcomeRead);

client.on('guildMemberAdd', (member) => {
  var serverId = member.guild.id;
  if (!welcomeFile[serverId]) {
    console.log('Welcome is disabled!');
  } else {
    let welcomeChannel = welcomeFile[serverId].channel,
    let setChannel = message.guild.channels.find(channel => channel.name === welcomeChannel);
    const embed = new Discord.RichEmbed()
      .setTitle("Test")
      .setAuthor("Test")
      .setColor(3447003)
      .setDescription("Test")
      .setThumbnail(message.author.avatarURL);
    member.guild.channels.get(setChannel).send({
      embed
    });
  }
});

错误与这一行有关

let setChannel = message.guild.channels.find(channel => channel.name === welcomeChannel);

我真的很想学习 JS,并且不断发现自己遇到了需要寻求帮助的砖墙。我也不确定你是否修复了我的message is not defined 我的代码实际上会做任何事情。

【问题讨论】:

  • 你在哪里定义消息?您必须定义消息变量才能使用它,否则是未定义的。
  • 我知道message is not defined 是什么意思,我的问题是我不确定如何定义它。无论如何,这个问题得到了回答。

标签: javascript node.js discord discord.js


【解决方案1】:

消息未定义,您应该寻找成员。

让 setChannel = member.guild.channels.find(channel => channel.name === welcomeChannel);

client.on('guildMemberAdd', (member) => {
    var serverId = member.guild.id;
    if (!welcomeFile[serverId]) {
      console.log('Welcome is disabled!')
    } else {
      let welcomeChannel = welcomeFile[serverId].channel
      let setChannel = member.guild.channels.find(channel => channel.name === welcomeChannel);
      const embed = new Discord.RichEmbed()
        .setTitle("Test")
        .setAuthor("Test")
        .setColor(3447003)
        .setDescription("Test")
        .setThumbnail(message.author.avatarURL)
        member.guild.channels.get(setChannel).send({embed});
    }
})

【讨论】:

  • 谢谢,我知道这可能是一个简单的修复,但看不到它!你知道为什么.setThumbnail(message.author.avatarURL) 行说消息未定义吗?还是我应该创建一个新帖子?
  • 'message' 仍未在此处定义。
猜你喜欢
  • 2020-09-10
  • 2021-10-09
  • 2020-05-18
  • 2020-09-07
  • 2021-05-05
  • 2020-02-22
  • 1970-01-01
  • 2021-06-03
相关资源
最近更新 更多