Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix IntegerOptionType Unmarshall #372

Closed
wants to merge 1 commit into from

Conversation

bitspill
Copy link

@bitspill bitspill commented Feb 1, 2023

All numerical types were using NumberOptionType rather than distinguishing IntegerOptionType which led to an unmarshalling error when using the int/uint variants

/x 12 -> option "x" expecting type 10, got 4

// Initialize bot connection
// Register a command for x
// Register route for x to cmdX

api.CreateCommandData{
	Name:        "x",
	Description: "x",
	&discord.IntegerOption{
		OptionName:  "x",
		Description: "Integer x",
		Required:    true,
	}
}

func (b *Bot) cmdX(ctx context.Context, data cmdroute.CommandData) *api.InteractionResponseData {
	var options struct {
		X int `discord:"x"`
	}

	if err := data.Options.Unmarshal(&options); err != nil {
		return errorResponse(err)
	}
	return &api.InteractionResponseData{
		Content:         option.NewNullableString(fmt.Sprintf("X was (%d)", options.X)),
		AllowedMentions: &api.AllowedMentions{}, // don't mention anyone
	}
}

Copy link
Owner

@diamondburned diamondburned left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, before I merge this PR, I think this is a breaking change. Can we modify the code to use a switch that accepts both types instead of using a map?

@bitspill
Copy link
Author

Ah yes good catch and idea, I'll do that when my current project wraps up in the next couple weeks.

@diamondburned
Copy link
Owner

Replaced by #421.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants