【问题标题】:RichEmbed discord.jsRichEmbed discord.js
【发布时间】:2020-05-18 11:50:33
【问题描述】:

对不起,我的英语不好,我是法国人

我正在尝试为我的投票 discord.js 机器人创建一个 RichEmbed 构造函数。我希望我的代码发送 RichEmbed,但是当我输入命令时没有任何反应,我只是收到以下错误消息:

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'client' of undefined

这是我的代码:

module.exports.run = async (bot, message, args) => {

  function extractAllText(str){
    const re = /"(.*?)"/g;
    const result = [];
    let current;
    while (current = re.exec(str)) {
      result.push(current.pop());
    }
    return result.length > 0
      ? result
      : [str];
  }

  result = extractAllText(message.content)

  //Here
  const embed = new Discord.MessageEmbed()
    .setColor('#0099ff')
    .setTitle(result[0])
    .setAuthor(message.author)
    .setDescription('Sondage')
    .setTimestamp()
    .setFooter('Vous pouvez voter en cliquant sur les réactions ci-dessous.');

  for (let i = 1; i < result.length; i++) {
    embed.addField(i, result[i])
  }

  message.channel.send(embed);

};

我尝试将 MessageEmbed() 替换为 RichEmbed(),但出现另一个错误:

UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message

我也尝试使用嵌入对象,但我找不到在这种嵌入中使用 for 循环的方法。

在我的文件顶部,我尝试写:

const Discord = require('discord.js')
const client = new Discord.Client({disableEveryone: true})

但是还是不行

感谢您阅读本文,祝您有美好的一天

【问题讨论】:

    标签: javascript discord.js


    【解决方案1】:

    我通过从 powershell 再次输入 yarn add discord.js 将 discord.js 更新到版本 12 来解决了这个问题(我认为对于 npm 应该是 npm install discord.js)。

    【讨论】:

      【解决方案2】:

      尝试在模块文件的顶部添加:

      const Discord = require('discord.js')
      

      或者,您可以尝试在 app.js/index.js 中修改它:

      commandFile.run(bot, message, args)
      

      与:

      commandFile.run(Client, bot, message, args)
      

      编辑:

      修改:

      let sEmbed = new Discord.MessageEmbed()
      

      与:

      let sEmbed = new Discord.RichEmbed()
      

      【讨论】:

      • 感谢您的回答,但我还有UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'client' of undefined
      • 用'bot'修改'client'!
      • js command.run(Client, bot, message, args); 这样好吗?我仍然有同样的错误
      • 这里是我的命令文件的代码:pastebin.com/JewHNRh3
      • 我尝试使用 RichEmbed() 修改 MessageEmbed() 但现在显示为 (node:33) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message
      猜你喜欢
      • 2020-07-24
      • 1970-01-01
      • 2020-09-23
      • 1970-01-01
      • 2020-02-15
      • 2020-02-23
      • 2020-06-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多