【问题标题】:Passing strings for the URL or the icon's URL for MessageEmbed#setAuthor is deprecated. Pass a sole object instead不推荐为 MessageEmbed#setAuthor 传递 URL 或图标 URL 的字符串。而是传递一个唯一的对象
【发布时间】:2022-01-09 16:44:22
【问题描述】:

我正在开发一个 Discord 机器人,如果用户输入某个命令,我的机器人将回复 embed

这是我嵌入的代码:

let embedInfo = {

    authorName: "My Discord Bot",

    authorLink: "the link for my image",

    thumbnailLink: "the link for the image",

    footer: "Invite us on Discord"
}

let reactivitySeriesInfo = {
    title: "The Reactivity Series of Metals",

    desc: "In chemistry, a reactivity series (or activity series) is an empirical, calculated, and structurally analytical progression of a series of metals, arranged by their \"reactivity\" from highest to lowest.",

    normalImage: "link",

    normalValency: "link",

    anagramValency: "link",

    anagram: "link"
}

module.exports = {
    name: 'chem rs nv',

    description: "To view the normal Reactivity series table, with element valencies.",

    execute(message, args) {

        let embed = new MessageEmbed()

        .setAuthor("My Discord Bot", embedInfo.authorLink)

        .setTitle("The Reactivity Series of Metals")

        .setDescription("In chemistry, a reactivity series (or activity series) is an empirical, calculated, and structurally analytical progression of a series of metals, arranged by their \"reactivity\" from highest to lowest.")

        .setImage(reactivitySeriesInfo.normalValency)

        .setTimestamp()

        .setFooter("Use db!invite to invite us on Discord")

        message.channel.send({embeds: [embed]}).catch(console.error)
    }
}

请注意,“图片”是我在Imgur. 上上传的图片的别名。图片链接和名称是我不想透露的。

每当我运行我的机器人脚本时,它都会显示此错误。我知道这个错误不会停止正在运行的脚本,这只是一个DeprecationWarning。使用命令时,这些命令仍然可以正常工作。

(node:2416) DeprecationWarning: Passing strings for the URL or the icon's URL for MessageEmbed#setAuthor is deprecated. Pass a sole object instead. (Use `node --trace-deprecation ...` to show where the warning was created)

但我无法弄清楚 JS 或 NodeJS 中唯一对象的含义。谁能解释一下什么是Sole Object?

【问题讨论】:

  • 是的,我在嵌入脚本之前使用了const {MessageEmbed} = require('discord.js')

标签: javascript node.js discord discord.js


【解决方案1】:

EmbedAuthorData 传递给setAuthor() 以避免使用已弃用的参数。

let author = {
    name: "My Discord Bot",
    url: "[author url here]",
    iconURL: embedInfo.authorLink
}

let embed = new MessageEmbed()
.setAuthor(author)
...

【讨论】:

  • 谢谢,帮了大忙!!
猜你喜欢
  • 2022-08-14
  • 1970-01-01
  • 2015-09-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-05
  • 1970-01-01
  • 2013-03-02
相关资源
最近更新 更多