typescript 尝试将按钮添加到Discord JS交互时出错,reply

gjmwrych  于 2023-05-30  发布在  TypeScript
关注(0)|答案(1)|浏览(117)

我目前有一个问题,添加按钮到我的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
            })
        ]
    })]
});

下面是我得到的错误:

[{
    "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"
        }
    ]
}]

我已经尝试了很多不同的方法,例如首先将它们存储在变量中,我已经尝试了不同的格式,例如使用.setStyle等。
我期望它不会返回错误,并允许我在不和谐的消息回复中添加一个按钮。

bxpogfeg

bxpogfeg1#

为其他有此问题的人找到了解决方案。在TypeScript中,你也需要添加这个。
所以应该是return interaction.reply({ content:运行channel命令时出错。请稍后再试。(${error}), ephemeral: true, components: [new ActionRowBuilder<ButtonBuilder>({ components: [ new ButtonBuilder({ customId: '1', label: 'yes', style: ButtonStyle.Success }) ] })] });

相关问题