【问题标题】:Bot copy the message url in discord.js机器人在 discord.js 中复制消息 url
【发布时间】:2022-06-10 23:10:21
【问题描述】:

bot 能否以某种方式复制他刚刚发送的消息的 url?我试图做类似的事情,但它没有工作

channel1.send("test",{
            embed:embed,
          });
const messageurl = client.message.cache.find(URL)
message.channel.send(`${messageurl}`)

【问题讨论】:

    标签: javascript discord discord.js


    【解决方案1】:

    使用这个:

    const msg = await channel1.send("test",{
                embed:embed,
              });
    channel1.send(`${msg.url}`)
    

    【讨论】:

      【解决方案2】:

      首先,在通道中发送消息的选项是字符串或对象。如果您使用了错误的方法,您的机器人只会将test 发送到文本通道。将其替换为 .send({ <options> }),以便您可以发送多个项目。

      第二,如果你使用discord.js v13,发送消息的嵌入选项必须是一个数组:

      channel.send({ embeds: [] });
      

      最后,<textChannel>.send() 方法返回一个 Promise 并发送消息。通过定义const msg = await channel1.send({ <options> });(Await 仅在异步函数中可用)来获取您的机器人发送的消息。现在我们可以访问消息的属性,例如IDurlauthor...等。您想要的URL 是msg.url。 这是最终代码:

      (async () => {
          const msg = await channel1.send({
                  content: "test",
                  embeds: [ embed ],
                });
          channel1.send(`${msg.url}`);
      })();
      

      希望这对您有所帮助,如果您对此答案仍有任何疑问,请发表评论。

      【讨论】:

        【解决方案3】:

        channel1.send({ content: `${msg.url}`, embeds: [embed] })

        【讨论】:

          猜你喜欢
          • 2018-06-05
          • 2021-02-01
          • 2021-12-13
          • 1970-01-01
          • 2022-01-24
          • 2021-06-26
          • 2020-09-08
          • 2018-04-29
          • 2020-07-18
          相关资源
          最近更新 更多