discordgo -发送TextInput作为MessageComponent返回“Invalid Form Body”,代码为“UNION_TYPE_CHOICES”

mmvthczy  于 2023-08-01  发布在  Go
关注(0)|答案(2)|浏览(126)

我们正在使用discordgo library开发一个带有Go语言的Discord机器人。我能够发送包含ActionRow,SelectMenu,Button组件的消息使用[DiscordSession].ChannelMessageSendComplex(chnlId, msg),但当我把TextInput组件内的消息,它返回400“无效的表单体”错误。
完整错误消息:

"HTTP 400 Bad Request, 
{\"code\": 50035, \"errors\": {\"components\": 
{\"0\": 
{\"components\": 
{\"0\": 
{\"_errors\": [
{\"code\": \"UNION_TYPE_CHOICES\", 
\"message\": \"Value of field \\\"type\\\" must be one of (2, 3, 5, 6, 7, 8).\"}]}}}}}, \"message\": \"Invalid Form Body\"}"

字符串
启动组件对象的“我的代码”:

components := []discordgo.MessageComponent{
        discordgo.ActionsRow{
            Components: []discordgo.MessageComponent{
                discordgo.TextInput{
                    CustomID:    "fd_text_short",
                    Label:       "Some Label",
                    Style:       discordgo.TextInputShort,
                    Placeholder: "test",
                    MinLength:   1,
                    MaxLength:   200,
                },
            },
        },
    }


发送消息的代码:

msgSend := &discordgo.MessageSend{
        Content:    "Some Content",
        Components: components,
    }
    _, err := session.ChannelMessageSendComplex(chnlId, msgSend)


我还使用了discordgo repo中的现有示例,并尝试添加文本应用程序命令来响应交互响应中的TextInput消息,但得到了相同的错误:

"text": func(s *discordgo.Session, i *discordgo.InteractionCreate) {
            err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
                Type: discordgo.InteractionResponseChannelMessageWithSource,
                Data: &discordgo.InteractionResponseData{
                    Content: "Please share any feedback you",
                    Flags:   discordgo.MessageFlagsEphemeral,
                    Components: []discordgo.MessageComponent{
                        discordgo.ActionsRow{
                            Components: []discordgo.MessageComponent{
                                discordgo.TextInput{
                                    CustomID: "fd_text_short_111",
                                    Label:    "Any feedback you have with CEO",
                                    Style: discordgo.TextInputParagraph,
                                    MinLength: 10,
                                    MaxLength: 300,
                                    Required:  true,
                                },
                            },
                        },
                    },
                },
            })

            if err != nil {
                panic(err)
            }
        },


我尝试遵循Discord API文档中对TextInput组件的所有考虑因素
任何帮助解决这个问题都是受欢迎的:)

jgovgodb

jgovgodb1#

我在discordgo频道here上问了这个问题,答案是:
不能在模态交互响应之外使用TextInput。
这意味着我们只能在Modals中使用TextInput,这是有意义的,因为在与用户的直接消息交互中,discord的输入框足以从用户那里获得文本。我不知道为什么这在Discord的文档中没有提到

ljo96ir5

ljo96ir52#

当我将TYPE discordgo.InteractionResponseChannelMessageWithSource更改为discordgo.InteractionResponseModal时,它对我有效。感谢Javad的建议!

相关问题