【问题标题】:Discord.js cannot send an empty messageDiscord.js 无法发送空消息
【发布时间】:2021-06-25 18:50:21
【问题描述】:

一段时间以来,我一直在尝试发送我的不和谐嵌入。但它不会发送,它总是出错。错误看起来像这样

DiscordAPIError: Cannot send an empty message
at RequestHandler.execute (C:\Users\me\Documents\npm-test\node_modules\discord.js\src\rest\RequestHandler.js:154:13)
at processTicksAndRejections (node:internal/process/task_queues:94:5)
at async RequestHandler.push (C:\Users\me\Documents\npm-

test\node_modules\discord.js\src\rest\RequestHandler.js:39:14) {
  method: 'post',
  path: '/channels/808286362100564002/messages',
  code: 50006,
  httpStatus: 400
}

但如果我尝试console.log MessageEmbed 对象我会得到这个

MessageEmbed {
  type: 'rich',
  title: 'What a cool embed',
  description: 'It has a descriptionfalse',
  url: null,
  color: 15417396,
  timestamp: 1617041078103,
  fields: [],
  thumbnail: null,
  image: null,
  video: null,
  author: null,
  provider: null,
  footer: { text: 'Even a footer', iconURL: undefined },
  files: []
}

我不知道这个问题的原因是什么,我试图在这里遵循其他人的解决方案,但没有任何效果):

我的自定义类

constructor(question: string,type: "number" | "string", optional: boolean, timeout?: number,description?: string,url?: string,color?: string | number | [number, number, number],timestamp?: Date,footer?: string){
        this.question = question;
        this.type = type;
        this.optional = optional;
        this.timeout = timeout;
        this.description = description;
        this.url = url;
        this.color = color;
        this.timestamp = timestamp;
        this.footer = footer;
    }

getEmbed(): MessageEmbed{
    const Embed = new MessageEmbed()
    Embed.setTitle(this.question)
    if(this.description) {Embed.setDescription(this.description + this.optional)}
    if(this.url) {Embed.setURL(this.url)}
    if(this.color) {Embed.setColor(this.color)}
    if(this.timestamp) {Embed.setTimestamp(this.timestamp)}
    if(this.footer) {Embed.setFooter(this.footer)}
    return Embed
}

客户端代码

let question = new PromptQuestion("What a cool embed", "number", false, 20,"It has a description",null,[235, 64, 52],Date.now(),"Even a footer")
let embed = question.getEmbed()
console.log(embed)

client.on("message", m => {
    if(m.author.bot) { return }
    m.reply(embed)
})

【问题讨论】:

  • 您也可以添加一些相关代码吗?
  • 当然,大部分都在自定义类中,但我会添加必要的东西
  • 奇怪,如果我在 PromptQuestion 类中弹出它,它对我来说很好:imgur.com/a/vXDxWU2
  • 是的,当我发送我手动制作的消息嵌入时,它也可以工作。但是对于类它不起作用,你认为我与打字稿有关吗
  • 我用let question = new PromptQuestionlet embed = question.getEmbed() 做到了,尽管我删除了流语法。

标签: node.js discord.js


【解决方案1】:

我想通了,或者至少是一个修复。 而不是返回embed,而是返回new MessageEmbed(embed)

【讨论】:

    【解决方案2】:

    在我的情况下,问题原来是我在频道中没有权限!权限与嵌入/外部内容有关,因此 Discord 可能由于缺少权限而默默地删除了嵌入,然后由于空消息而出错。在某些消息组合最终显示缺少权限错误后,我得到了一个提示,这是权限。

    TL;DR:检查您的权限,我们的频道除了发送拒绝消息外,什么都有,这不是一个好主意。

    如果不确定,请尝试使用其他频道或在 PM 中发送消息(如msg.author.send

    【讨论】:

      猜你喜欢
      • 2020-01-25
      • 2022-01-20
      • 2021-11-02
      • 2021-12-25
      • 2021-12-01
      • 2020-10-09
      • 1970-01-01
      • 1970-01-01
      • 2020-10-01
      相关资源
      最近更新 更多