fixed a bug

This commit is contained in:
2025-04-08 10:59:37 -04:00
parent fc3588b1d0
commit e003afab6d
2 changed files with 36 additions and 19 deletions
+25 -19
View File
@@ -167,25 +167,32 @@ func HandleReactionRole(s *discordgo.Session, i *discordgo.InteractionCreate) {
}
options := i.ApplicationCommandData().Options
count := int(options[0].IntValue())
// Determine style based on the additional option; default to primary.
style := "primary"
if len(options) > 1 {
styleOpt := options[1]
if val := styleOpt.StringValue(); val != "" {
style = val
}
}
// Extract count (required - type Integer)
countOpt := helpers.GetOption(options, "count")
if countOpt == nil {
helpers.HandleError(s, i, fmt.Errorf("missing count option"))
return
}
count := int(countOpt.IntValue())
targetMsgID := ""
if len(options) > 2 {
opt := options[2]
if val := opt.StringValue(); val != "" {
targetMsgID = val
reactionRoleTarget[i.Member.User.ID] = targetMsgID
}
}
// Determine style based on the "style" option; default to "primary"
style := "primary"
if opt := helpers.GetOption(options, "style"); opt != nil {
if val := opt.StringValue(); val != "" {
style = val
}
}
// Extract target message ID from the "message_id" option if available.
targetMsgID := ""
if opt := helpers.GetOption(options, "message_id"); opt != nil {
if val := opt.StringValue(); val != "" {
targetMsgID = val
// Store the target message ID keyed by the user's ID.
reactionRoleTarget[i.Member.User.ID] = targetMsgID
}
}
// Build modal components: for each pair, add two text inputs (each in its own action row).
modalComponents := []discordgo.MessageComponent{}
@@ -265,9 +272,8 @@ func HandleReactionRoleModalSubmit(s *discordgo.Session, i *discordgo.Interactio
btnStyle := mapStyle(styleStr)
log.Default().Println(targetMsgID, targetChannelID)
data := i.ModalSubmitData()
// There will be two action rows per pair.
count := len(data.Components) / 2
var buttons []discordgo.MessageComponent
+11
View File
@@ -2,8 +2,19 @@ package helpers
import (
"fmt"
"github.com/bwmarrin/discordgo"
)
func CreateMessageLink(guildID, channelID, messageID string) string {
return fmt.Sprintf("https://discord.com/channels/%s/%s/%s", guildID, channelID, messageID)
}
func GetOption(options []*discordgo.ApplicationCommandInteractionDataOption, name string) *discordgo.ApplicationCommandInteractionDataOption {
for _, opt := range options {
if opt.Name == name {
return opt
}
}
return nil
}