【问题标题】:How to get message link through Discord.js v12?如何通过 Discord.js v12 获取消息链接?
【发布时间】:2021-07-16 09:23:31
【问题描述】:

我正在为拥有超过 12k 名成员的 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: Cannot read property 'get' of null`

【问题讨论】:

    标签: javascript discord.js


    【解决方案1】:

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

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

    【讨论】:

    • 这是正确的解决方案,谢谢!
    猜你喜欢
    • 2018-09-01
    • 2021-01-11
    • 1970-01-01
    • 2021-04-19
    • 2020-11-28
    • 2021-04-06
    • 2021-01-03
    • 1970-01-01
    • 2020-10-25
    相关资源
    最近更新 更多