Cob*_*lls 0 typescript discord.js
我目前在向我的 Discord JS 项目添加按钮时遇到问题,我正在使用 Typescript 和 Discord JS v14 来制作机器人。
我当前的问题是添加按钮,它给了我一个很长的错误,我无法自己找到解决方案,而且我还没有在网上找到解决方案。
是的,所有内容都已包含在内,并且机器人上的所有内容都正常运行,我只是在尝试添加按钮时收到错误。
这是有问题的代码片段:
return interaction.reply({
content: `There was an error while running the channel command. Please try again later. (${error})`,
ephemeral: true,
components: [new ActionRowBuilder({
components: [
new ButtonBuilder({
customId: '1',
label: 'yes',
style: ButtonStyle.Success
})
]
})]
});
Run Code Online (Sandbox Code Playgroud)
这是我收到的错误:
[{
"resource": "/c:/Users/Coby/Documents/GitHub/franksbot/src/commands/chanell.ts",
"owner": "typescript",
"code": "2769",
"severity": 8,
"message": "No overload matches this call.\n Overload 1 of 2, '(options: InteractionReplyOptions & { fetchReply: true; }): Promise<Message<boolean>>', gave the following error.\n Type 'ActionRowBuilder<AnyComponentBuilder>' is not assignable to type 'APIActionRowComponent<APIMessageActionRowComponent> | JSONEncodable<APIActionRowComponent<APIMessageActionRowComponent>> | ActionRowData<...>'.\n Property 'type' is missing in type 'ActionRowBuilder<AnyComponentBuilder>' but required in type 'ActionRowData<MessageActionRowComponentData | MessageActionRowComponentBuilder>'.\n Overload 2 of 2, '(options: string | InteractionReplyOptions | MessagePayload): Promise<InteractionResponse<boolean>>', gave the following error.\n Type 'ActionRowBuilder<AnyComponentBuilder>' is not assignable to type 'APIActionRowComponent<APIMessageActionRowComponent> | JSONEncodable<APIActionRowComponent<APIMessageActionRowComponent>> | ActionRowData<...>'.",
"source": "ts",
"startLineNumber": 79,
"startColumn": 26,
"endLineNumber": 87,
"endColumn": 15,
"relatedInformation": [
{
"startLineNumber": 267,
"startColumn": 3,
"endLineNumber": 267,
"endColumn": 7,
"message": "'type' is declared here.",
"resource": "/c:/Users/Coby/Documents/GitHub/franksbot/node_modules/discord.js/typings/index.d.ts"
}
]
}]
Run Code Online (Sandbox Code Playgroud)
我尝试了许多不同的方法,例如首先将它们存储在变量中,我尝试了不同的格式,例如使用 .setStyle 等。
我希望它不会返回错误,并允许我在不和谐的消息回复中添加一个按钮。
在 TypeScript 中,您需要指定您的ActionRow将包含ButtonBuilder.
你需要使用ActionRowBuilder<ButtonBuilder>而不是仅仅ActionRowBuilder
因此,根据您的示例,它会给出:
return interaction.reply({
content: `There was an error while running the channel command. Please try again later. (${error})`,
ephemeral: true,
components: [new ActionRowBuilder<ButtonBuilder>({
components: [
new ButtonBuilder({
customId: '1',
label: 'yes',
style: ButtonStyle.Success
})
]
})]
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1046 次 |
| 最近记录: |