【问题标题】:Discord command: args.join is not a functionDiscord 命令:args.join 不是函数
【发布时间】:2021-05-12 12:26:59
【问题描述】:

我希望我的机器人将嵌入的 webhook 发送到不和谐频道,这是我的代码,但我不知道如何解决此错误

TypeError: args.join is not a function

const { Command } = require('discord.js-commando');
const { WebhookClient, MessageEmbed } = require('discord.js')

module.exports = class reportCommand extends Command {
  constructor(client) {
    super(client, {
      name: 'report',
      group: 'help',
      memberName: 'report',
      description: 'Report some bug about me.',
    });
  }
  
    async run (client, message, args) { 
      const wc = new WebhookClient('0000000000000', '000000000000')
      const embed = new MessageEmbed()
          .setTitle("this is an embed")
          .setColor('GREEN')
          .setTimestamp()
          .setDescription(args.join(" "))
  wc.send({
      username : message.author.tag,
      avatarURL : message.author.displayAvatarURL({ dynamic : true }),
      embeds : [embed]
  })
  }
}

顺便说一句,我已经试过了

args: [
        {
          key: 'reason',
          prompt:
            'Whats your problem?',
          type: 'string'
        },
]

Embed
.setDescription(reason)

但它仍然不起作用,我在嵌入消息的描述中得到另一个undefined,如果不是那个可能是displayAvatarURL,所以我真的不知道该怎么办或者如何修复它,因为如果我删除 displayAvatarURL,消息仍将是 indefinied

【问题讨论】:

    标签: node.js command discord.js embed webhooks


    【解决方案1】:

    根据docsCommand.run() 方法的参数如下---messageargsfromPatternresult 按顺序排列(result 是可选的)

       run(message, args, fromPattern [,result])
    

    您实际上是在尝试访问第三个参数的join() 方法---fromPattern--- 因为fromPattern 是一个布尔值(true /false) 变量和join() 是一个数组方法

    【讨论】:

    • Join是数组方法
    • @Elitezen 哎呀。对不起错字。谢谢指出
    猜你喜欢
    • 2020-03-13
    • 2020-12-15
    • 2021-08-28
    • 1970-01-01
    • 2020-07-17
    • 1970-01-01
    • 2021-05-22
    相关资源
    最近更新 更多