如何通过 Discord.js v12 获取消息链接?

时间:2021-04-22 07:11:41

标签: javascript discord.js

我正在为超过 12,000 名成员的 Discord 服务器创建一个日志系统。我想实现的是,每当主持人使用 .lock 命令时,机器人都会向日志通道发送一条消息 DM 就是我。两者都有效,但我不知道如何附加消息 url,以便我可以点击它并立即跳转到 .lock 命令本身,以便我可以查看发生了什么。

这是我迄今为止的代码:

    // Message url to be used in logging later.
    const msgURL = 'empty';

    // Send lock message
    const embed = new Discord.MessageEmbed()
      .setTitle("LOCKDOWN")
      .setColor('#ff0000')
      .setDescription("There have been a large number of infringements in this channel. Please be patient as we review the sent messages and take appropriate action.")
      .setFooter("Please do not DM staff asking when the lockdown will be over. ");
    message.channel.send({embed}).then(msgURL => {
      msgURL = embed.url;
    })

      // Send unlock notification to #staff-logs.

      // async method to get the channel id (in case of delay.)
     function getStaffLogChannel(){
        return message.guild.channels.cache.get('ID');
      }

      // Staff logs channel
      let staffLogs = await getStaffLogChannel();
      
      // User who issued the command
      let commandIssuer = message.member.user.tag;

      // message published in staff-logs
      staffLogs.send(commandIssuer + " has used the **.lock** command in: " + message.channel.name)
      
      // send notification in DM
      client.users.cache.get('ID').send(commandIssuer + " has used the **.lock** command in: " + message.channel.name + " ( " + msgURL + " )");

我也试图改变

        message.channel.send({embed}).then(msgURL => {
      msgURL = embed.url;
    })

到:

        message.channel.send({embed}).then(msgURL => {
      msgURL = embed.url.get;
    })

但不幸的是,这也不起作用。在这里你会得到这个错误:

<块引用>

TypeError: 无法读取 null 的属性 'get'

1 个答案:

答案 0 :(得分:1)

您可以只使用 Message#url。不需要 .get()

您正在尝试获取嵌入的 URL,而不是消息。