【问题标题】:Can you use an array for MessageEmbed#setDescription?您可以为 MessageEmbed#setDescription 使用数组吗?
【发布时间】:2021-01-14 14:01:50
【问题描述】:

作为一个有趣的项目,我创建了一个我自己的不和谐机器人。我正在尝试制作一个待办事项列表(一旦我输入-todo command,机器人就会回复一个已制作的待办事项列表)。我想在嵌入消息框中放置一个数组。

我可以使用.setDescription(array[]) 吗?还是有其他方法可以在嵌入框中显示它?它适用于短信,但不适用于嵌入。

module.exports = {
  name: 'todolist',
  description: 'Sends a to do list in the channel',
  execute(message, args) {
    let i;
    for(i = 0 ; i < todolist.length; i++){
      message.channel.send(`${todolist[i]}`);
    }
  },
};

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    Discord.js v13

    不,您不能使用.setDescription(array)。 Discord.js v13 stopped converting non-strings into strings 使用这些方法来避免 [object Object] 和其他不希望的结果。

    您需要先将数组转换为字符串(例如,.setDescription(array.join('\n')) 复制 Discord.js v12 行为)。

    Discord.js v12

    是的,您可以使用.setDescription(array)

    setDescription 接受StringResolvable 并使用解析后的字符串作为嵌入描述。这与TextBasedChannel#send 的行为方式相同:数组以新行连接。

    【讨论】:

      猜你喜欢
      • 2020-09-10
      • 1970-01-01
      • 2012-09-22
      • 1970-01-01
      • 2020-11-26
      • 1970-01-01
      • 2020-03-23
      • 1970-01-01
      • 2011-05-24
      相关资源
      最近更新 更多