所以我试图将图像附加到不和谐嵌入(最好作为缩略图)。图像本地存储在我的硬盘上。我目前正在这样做:
attachment = await new discord.MessageAttachment('serverFavicon.png', 'favicon.png');
embed.setThumbnail(attachment);
这将返回此错误而不发送嵌入:
(node:60598) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body
embed.thumbnail.url: Could not interpret "{'attachment': 'serverFavicon.png', 'name': 'favicon.png'}" as string.
at RequestHandler.execute (/Users/manders/Desktop/Bots/Minecraft Server Discord Bot/node_modules/discord.js/src/rest/RequestHandler.js:154:13)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async RequestHandler.push (/Users/manders/Desktop/Bots/Minecraft Server Discord Bot/node_modules/discord.js/src/rest/RequestHandler.js:39:14)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:60598) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:60598) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
奇怪的是如果我这样做了
message.channel.send('Image', attachment);
它将成功发送图像。
所以我想知道为什么它不会附加到嵌入,但它可以发送到频道。
答案 0 :(得分:1)
setThumbnail
只接受一个字符串(图片的 URL),而不接受一个 MessageAttachment
。
在您的示例中,您可以简单地使用图像的 URL:
embed.setThumbnail('serverFavicon.png');
如果要重命名图片,可以在发送消息时附加 MessageAttachment
并使用 attachment://image-name.png
作为缩略图 URL:
// You also don't need to use await here; constructors can't be async
const attachment = new discord.MessageAttachment('serverFavicon.png', 'favicon.png');
embed.setThumbnail('attachment://favicon.png');
// ...
message.channel.send({embed, files: [attachment]});
有关在嵌入中使用附件的详细信息,请参阅 Discord developer docs。