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
+15 -9
View File
@@ -167,22 +167,29 @@ func HandleReactionRole(s *discordgo.Session, i *discordgo.InteractionCreate) {
} }
options := i.ApplicationCommandData().Options options := i.ApplicationCommandData().Options
count := int(options[0].IntValue())
// Determine style based on the additional option; default to primary. // 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())
// Determine style based on the "style" option; default to "primary"
style := "primary" style := "primary"
if len(options) > 1 { if opt := helpers.GetOption(options, "style"); opt != nil {
styleOpt := options[1] if val := opt.StringValue(); val != "" {
if val := styleOpt.StringValue(); val != "" {
style = val style = val
} }
} }
// Extract target message ID from the "message_id" option if available.
targetMsgID := "" targetMsgID := ""
if len(options) > 2 { if opt := helpers.GetOption(options, "message_id"); opt != nil {
opt := options[2]
if val := opt.StringValue(); val != "" { if val := opt.StringValue(); val != "" {
targetMsgID = val targetMsgID = val
// Store the target message ID keyed by the user's ID.
reactionRoleTarget[i.Member.User.ID] = targetMsgID reactionRoleTarget[i.Member.User.ID] = targetMsgID
} }
} }
@@ -265,9 +272,8 @@ func HandleReactionRoleModalSubmit(s *discordgo.Session, i *discordgo.Interactio
btnStyle := mapStyle(styleStr) btnStyle := mapStyle(styleStr)
log.Default().Println(targetMsgID, targetChannelID)
data := i.ModalSubmitData() data := i.ModalSubmitData()
// There will be two action rows per pair. // There will be two action rows per pair.
count := len(data.Components) / 2 count := len(data.Components) / 2
var buttons []discordgo.MessageComponent var buttons []discordgo.MessageComponent
+11
View File
@@ -2,8 +2,19 @@ package helpers
import ( import (
"fmt" "fmt"
"github.com/bwmarrin/discordgo"
) )
func CreateMessageLink(guildID, channelID, messageID string) string { func CreateMessageLink(guildID, channelID, messageID string) string {
return fmt.Sprintf("https://discord.com/channels/%s/%s/%s", guildID, channelID, messageID) 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
}