【发布时间】:2021-08-09 02:40:40
【问题描述】:
我正在尝试将按钮附加到我的测试嵌入的底部,但是我收到了错误。
导致错误的代码:
module.exports = {
name: 'test',
description: 'A simple test command for MessageButtons',
/**
* @param {object} message The message that was sent
* @param {string} prefix The servers prefix
* @param {Client} client The bots client
*/
async execute(message, _prefix, client) {
const { MessageEmbed, MessageButton } = require('discord.js');
let button1 = new MessageButton();
button1.setLabel('Yes');
button1.setStyle('PRIMARY');
let button2 = new MessageButton()
button2.setLabel('No');
button2.setStyle('PRIMARY');
let embed = new MessageEmbed()
.setDescription('This is a test embed');
message.channel.send({ embeds: [embed], components: [button1, button2] });
}
}
错误:
D:\Projects\Test\node_modules\discord.js\src\rest\RequestHandler.js:298
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Invalid Form Body
components[0]: The specified component type is invalid in this context
components[1]: The specified component type is invalid in this context
at RequestHandler.execute (D:\Projects\Test\node_modules\discord.js\src\rest\RequestHandler.js:298:13)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (D:\Projects\Test\node_modules\discord.js\src\rest\RequestHandler.js:50:14)
at async TextChannel.send (D:\Projects\Test\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:171:15)
at async Object.execute (D:\Projects\Test\commands\test.js:14:13) {
method: 'post',
path: '/channels/826774490650247178/messages',
code: 50035,
httpStatus: 400,
requestData: {
json: {
content: undefined,
tts: false,
nonce: undefined,
embeds: [
{
title: null,
type: 'rich',
description: 'This is a test embed',
url: null,
timestamp: 0,
color: null,
fields: [],
thumbnail: null,
image: null,
author: null,
footer: null
}
],
components: [
{
custom_id: null,
disabled: false,
emoji: null,
label: 'Yes',
style: 1,
type: 2,
url: null
},
{
custom_id: null,
disabled: false,
emoji: null,
label: 'No',
style: 1,
type: 2,
url: null
}
],
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined
},
files: []
}
}
【问题讨论】:
标签: node.js discord.js