我一直在尝试发送我的不和谐嵌入。但它不会发送,它总是错误。错误看起来像这样
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)
})
答案 0 :(得分:0)
我想通了,或者至少是修复了。
而不是返回 embed
return new MessageEmbed(embed)
答案 1 :(得分:0)
就我而言,问题原来是我在频道中没有权限!权限与嵌入/外部内容有关,因此 Discord 可能由于缺少权限而默默删除了嵌入,然后由于空消息而出错。在某些消息组合最终闪现丢失权限错误后,我得到提示,这是权限。
TL;DR:检查您的权限,我们的频道除了发送拒绝消息外,还有一切,这不是一个好主意。
如果不确定,请尝试不同的频道或在 PM 中发送消息(例如 msg.author.send
)