【发布时间】: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 PromptQuestion和let embed = question.getEmbed()做到了,尽管我删除了流语法。
标签: node.js discord.js