Reputation: 357
We are developing a Discord bot with Go language using discordgo library. I was able to send messages containing ActionRow, SelectMenu, Button components using [DiscordSession].ChannelMessageSendComplex(chnlId, msg)
but when I put TextInput component inside the message, it's returning 400 "Invalid Form Body" error.
Complete Error Message:
"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\"}"
My Code to initiate the components object:
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,
},
},
},
}
The code to send message:
msgSend := &discordgo.MessageSend{
Content: "Some Content",
Components: components,
}
_, err := session.ChannelMessageSendComplex(chnlId, msgSend)
I also used existing samples in discordgo repo for components here and tried to add text application command to respond a TextInput mesage in interaction response, but getting same error:
"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)
}
},
I tried to follow all considerations Discord API Documentation have for TextInput component here
Any help to figure out this problem is welcome :)
Upvotes: 1
Views: 1074
Reputation: 1
It works for me when I change TYPE discordgo.InteractionResponseChannelMessageWithSource
to discordgo.InteractionResponseModal
.
Thanks Javad for the suggestion!
Upvotes: 0
Reputation: 357
I asked this question in discordgo channel here and the answer was:
You cannot use TextInput outside a modal interaction response.
it means we only can use TextInput with Modals and it makes sense as in direct message interaction with users, discord's input box is good enough to get text from user. I don't know why this is not mentioned in Discord documentations here
Upvotes: 2