Skip to content

Commit

Permalink
feat: chose a specific type in channel_selection
Browse files Browse the repository at this point in the history
  • Loading branch information
idrista committed Oct 18, 2023
1 parent 57c1f5c commit 3936432
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/select_menus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
'channel_select', false, nil, nil, nil, nil,
Discordrb::Components::View.new do |builder|
builder.row do |r|
r.channel_select(custom_id: 'channel_select', placeholder: 'Test of ChannelSelect', max_values: 3)
r.channel_select(custom_id: 'channel_select', placeholder: 'Test of ChannelSelect', max_values: 3, channel_types: [:guild_text, :guild_voice])
end
end
)
Expand Down
30 changes: 28 additions & 2 deletions lib/discordrb/webhooks/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ class Discordrb::Webhooks::View
channel_select: 8
}.freeze

# Channel types.
# @see https://discord.com/developers/docs/resources/channel#channel-object-channel-types
CHANNEL_TYPES = {
guild_text: 0,
dm: 1,
guild_voice: 2,
group_dm: 3,
guild_category: 4,
guild_announcement: 5,
announcement_thread: 10,
public_thread: 11,
private_thread: 12,
guild_stage_voice: 13,
guild_directory: 14,
guild_forum: 15,
guild_media: 16
}.freeze

# This builder is used when constructing an ActionRow. All current components must be within an action row, but this can
# change in the future. A message can have 5 action rows, each action row can hold a weight of 5. Buttons have a weight of 1,
# and dropdowns have a weight of 5.
Expand Down Expand Up @@ -114,8 +132,16 @@ def mentionable_select(custom_id:, placeholder: nil, min_values: nil, max_values
# @param min_values [Integer, nil] The minimum amount of values a user must select.
# @param max_values [Integer, nil] The maximum amount of values a user can select.
# @param disabled [true, false, nil] Grey out the component to make it unusable.
def channel_select(custom_id:, placeholder: nil, min_values: nil, max_values: nil, disabled: nil)
@components << SelectMenuBuilder.new(custom_id, [], placeholder, min_values, max_values, disabled, select_type: :channel_select).to_h
# @param channel_types [Array<CHANNEL_TYPES>, nil] Display only the specific channel type(s).
def channel_select(custom_id:, placeholder: nil, min_values: nil, max_values: nil, disabled: nil, channel_types: nil)
builder = SelectMenuBuilder.new(custom_id, [], placeholder, min_values, max_values, disabled, select_type: :channel_select).to_h

if channel_types
types_selected = CHANNEL_TYPES.values_at(*channel_types)
builder[:channel_types] = types_selected
end

@components << builder
end

# @!visibility private
Expand Down

0 comments on commit 3936432

Please sign in to comment.