fixed a bug
This commit is contained in:
@@ -167,25 +167,32 @@ 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)
|
||||||
style := "primary"
|
countOpt := helpers.GetOption(options, "count")
|
||||||
if len(options) > 1 {
|
if countOpt == nil {
|
||||||
styleOpt := options[1]
|
helpers.HandleError(s, i, fmt.Errorf("missing count option"))
|
||||||
if val := styleOpt.StringValue(); val != "" {
|
return
|
||||||
style = val
|
}
|
||||||
}
|
count := int(countOpt.IntValue())
|
||||||
}
|
|
||||||
|
|
||||||
targetMsgID := ""
|
// Determine style based on the "style" option; default to "primary"
|
||||||
if len(options) > 2 {
|
style := "primary"
|
||||||
opt := options[2]
|
if opt := helpers.GetOption(options, "style"); opt != nil {
|
||||||
if val := opt.StringValue(); val != "" {
|
if val := opt.StringValue(); val != "" {
|
||||||
targetMsgID = val
|
style = val
|
||||||
reactionRoleTarget[i.Member.User.ID] = targetMsgID
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// 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).
|
// Build modal components: for each pair, add two text inputs (each in its own action row).
|
||||||
modalComponents := []discordgo.MessageComponent{}
|
modalComponents := []discordgo.MessageComponent{}
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user