Skip to content

Commit b1d3442

Browse files
authored
fix small component issues (#475)
1 parent 419fd31 commit b1d3442

File tree

2 files changed

+44
-12
lines changed

2 files changed

+44
-12
lines changed

discord/component.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,7 @@ var (
14101410
_ SectionSubComponent = (*UnknownComponent)(nil)
14111411
_ SectionAccessoryComponent = (*UnknownComponent)(nil)
14121412
_ ContainerSubComponent = (*UnknownComponent)(nil)
1413+
_ LabelSubComponent = (*UnknownComponent)(nil)
14131414
)
14141415

14151416
// UnknownComponent is a component that is not recognized by the library.
@@ -1475,3 +1476,4 @@ func (UnknownComponent) selectMenuComponent() {}
14751476
func (UnknownComponent) containerSubComponent() {}
14761477
func (UnknownComponent) sectionSubComponent() {}
14771478
func (UnknownComponent) sectionAccessoryComponent() {}
1479+
func (UnknownComponent) labelSubComponent() {}

discord/select_menu.go

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var (
2121
_ Component = (*StringSelectMenuComponent)(nil)
2222
_ InteractiveComponent = (*StringSelectMenuComponent)(nil)
2323
_ SelectMenuComponent = (*StringSelectMenuComponent)(nil)
24+
_ LabelSubComponent = (*StringSelectMenuComponent)(nil)
2425
)
2526

2627
// NewStringSelectMenu builds a new SelectMenuComponent from the provided values
@@ -43,10 +44,11 @@ type StringSelectMenuComponent struct {
4344
// MaxValues is the maximum number of options that can be selected.
4445
// Defaults to 1. Maximum is 25.
4546
MaxValues int `json:"max_values,omitempty"`
46-
Disabled bool `json:"disabled,omitempty"`
4747
Options []StringSelectMenuOption `json:"options,omitempty"`
4848
// Required Indicates if the select menu is required to submit the Modal.
49-
Required bool `json:"required,omitempty"`
49+
Required bool `json:"required"`
50+
// Disabled whether the select menu is disabled (only supported in messages)
51+
Disabled bool `json:"disabled"`
5052
// Values is only set when the StringSelectMenuComponent is received from an InteractionTypeModalSubmit
5153
Values []string `json:"values,omitempty"`
5254
}
@@ -153,8 +155,8 @@ func (c StringSelectMenuComponent) RemoveOption(index int) StringSelectMenuCompo
153155
}
154156

155157
// WithID returns a new StringSelectMenuComponent with the provided ID
156-
func (c StringSelectMenuComponent) WithID(i int) StringSelectMenuComponent {
157-
c.ID = i
158+
func (c StringSelectMenuComponent) WithID(id int) StringSelectMenuComponent {
159+
c.ID = id
158160
return c
159161
}
160162

@@ -233,7 +235,8 @@ type UserSelectMenuComponent struct {
233235
DefaultValues []SelectMenuDefaultValue `json:"default_values,omitempty"`
234236
MinValues *int `json:"min_values,omitempty"`
235237
MaxValues int `json:"max_values,omitempty"`
236-
Disabled bool `json:"disabled,omitempty"`
238+
// Disabled whether the select menu is disabled (only supported in messages)
239+
Disabled bool `json:"disabled"`
237240
}
238241

239242
func (c UserSelectMenuComponent) MarshalJSON() ([]byte, error) {
@@ -329,6 +332,12 @@ func (c UserSelectMenuComponent) RemoveDefaultValue(index int) UserSelectMenuCom
329332
return c
330333
}
331334

335+
// WithID returns a new UserSelectMenuComponent with the provided ID
336+
func (c UserSelectMenuComponent) WithID(id int) UserSelectMenuComponent {
337+
c.ID = id
338+
return c
339+
}
340+
332341
var (
333342
_ Component = (*UserSelectMenuComponent)(nil)
334343
_ InteractiveComponent = (*UserSelectMenuComponent)(nil)
@@ -350,7 +359,8 @@ type RoleSelectMenuComponent struct {
350359
DefaultValues []SelectMenuDefaultValue `json:"default_values,omitempty"`
351360
MinValues *int `json:"min_values,omitempty"`
352361
MaxValues int `json:"max_values,omitempty"`
353-
Disabled bool `json:"disabled,omitempty"`
362+
// Disabled whether the select menu is disabled (only supported in messages)
363+
Disabled bool `json:"disabled"`
354364
}
355365

356366
func (c RoleSelectMenuComponent) MarshalJSON() ([]byte, error) {
@@ -446,6 +456,12 @@ func (c RoleSelectMenuComponent) RemoveDefaultValue(index int) RoleSelectMenuCom
446456
return c
447457
}
448458

459+
// WithID returns a new RoleSelectMenuComponent with the provided ID
460+
func (c RoleSelectMenuComponent) WithID(id int) RoleSelectMenuComponent {
461+
c.ID = id
462+
return c
463+
}
464+
449465
var (
450466
_ Component = (*MentionableSelectMenuComponent)(nil)
451467
_ InteractiveComponent = (*MentionableSelectMenuComponent)(nil)
@@ -467,7 +483,8 @@ type MentionableSelectMenuComponent struct {
467483
DefaultValues []SelectMenuDefaultValue `json:"default_values,omitempty"`
468484
MinValues *int `json:"min_values,omitempty"`
469485
MaxValues int `json:"max_values,omitempty"`
470-
Disabled bool `json:"disabled,omitempty"`
486+
// Disabled whether the select menu is disabled (only supported in messages)
487+
Disabled bool `json:"disabled"`
471488
}
472489

473490
func (c MentionableSelectMenuComponent) MarshalJSON() ([]byte, error) {
@@ -560,6 +577,12 @@ func (c MentionableSelectMenuComponent) RemoveDefaultValue(index int) Mentionabl
560577
return c
561578
}
562579

580+
// WithID returns a new MentionableSelectMenuComponent with the provided ID
581+
func (c MentionableSelectMenuComponent) WithID(id int) MentionableSelectMenuComponent {
582+
c.ID = id
583+
return c
584+
}
585+
563586
var (
564587
_ Component = (*ChannelSelectMenuComponent)(nil)
565588
_ InteractiveComponent = (*ChannelSelectMenuComponent)(nil)
@@ -581,8 +604,9 @@ type ChannelSelectMenuComponent struct {
581604
DefaultValues []SelectMenuDefaultValue `json:"default_values,omitempty"`
582605
MinValues *int `json:"min_values,omitempty"`
583606
MaxValues int `json:"max_values,omitempty"`
584-
Disabled bool `json:"disabled,omitempty"`
585607
ChannelTypes []ChannelType `json:"channel_types,omitempty"`
608+
// Disabled whether the select menu is disabled (only supported in messages)
609+
Disabled bool `json:"disabled"`
586610
}
587611

588612
func (c ChannelSelectMenuComponent) MarshalJSON() ([]byte, error) {
@@ -684,9 +708,15 @@ func (c ChannelSelectMenuComponent) RemoveDefaultValue(index int) ChannelSelectM
684708
return c
685709
}
686710

711+
// WithID returns a new ChannelSelectMenuComponent with the provided ID
712+
func (c ChannelSelectMenuComponent) WithID(id int) ChannelSelectMenuComponent {
713+
c.ID = id
714+
return c
715+
}
716+
687717
type SelectMenuDefaultValue struct {
688-
ID snowflake.ID `json:"id"`
689718
Type SelectMenuDefaultValueType `json:"type"`
719+
ID snowflake.ID `json:"id"`
690720
}
691721

692722
type SelectMenuDefaultValueType string
@@ -700,23 +730,23 @@ const (
700730
// NewSelectMenuDefaultUser returns a new SelectMenuDefaultValue of type SelectMenuDefaultValueTypeUser
701731
func NewSelectMenuDefaultUser(id snowflake.ID) SelectMenuDefaultValue {
702732
return SelectMenuDefaultValue{
703-
ID: id,
704733
Type: SelectMenuDefaultValueTypeUser,
734+
ID: id,
705735
}
706736
}
707737

708738
// NewSelectMenuDefaultRole returns a new SelectMenuDefaultValue of type SelectMenuDefaultValueTypeRole
709739
func NewSelectMenuDefaultRole(id snowflake.ID) SelectMenuDefaultValue {
710740
return SelectMenuDefaultValue{
711-
ID: id,
712741
Type: SelectMenuDefaultValueTypeRole,
742+
ID: id,
713743
}
714744
}
715745

716746
// NewSelectMenuDefaultChannel returns a new SelectMenuDefaultValue of type SelectMenuDefaultValueTypeChannel
717747
func NewSelectMenuDefaultChannel(id snowflake.ID) SelectMenuDefaultValue {
718748
return SelectMenuDefaultValue{
719-
ID: id,
720749
Type: SelectMenuDefaultValueTypeChannel,
750+
ID: id,
721751
}
722752
}

0 commit comments

Comments
 (0)