Class: Discordrb::ChannelTag

Inherits:
Object
  • Object
show all
Includes:
IDObject
Defined in:
lib/discordrb/data/channel_tag.rb

Overview

A forum or media tag that can be applied to threads.

Instance Attribute Summary collapse

Attributes included from IDObject

#id

Instance Method Summary collapse

Methods included from IDObject

#==, #creation_time, synthesise

Instance Attribute Details

#channelChannel (readonly)

Returns the channel associated with the channel tag.

Returns:

  • (Channel)

    the channel associated with the channel tag.



12
13
14
# File 'lib/discordrb/data/channel_tag.rb', line 12

def channel
  @channel
end

#moderatedtrue, false (readonly) Also known as: moderated?

Returns whether or not the channel tag is moderated.

Returns:

  • (true, false)

    whether or not the channel tag is moderated.



15
16
17
# File 'lib/discordrb/data/channel_tag.rb', line 15

def moderated
  @moderated
end

#nameString (readonly)

Returns the 1-20 character name of the channel tag.

Returns:

  • (String)

    the 1-20 character name of the channel tag.



9
10
11
# File 'lib/discordrb/data/channel_tag.rb', line 9

def name
  @name
end

Instance Method Details

#delete(reason: nil) ⇒ nil

Permenantly delete the channel tag.

Parameters:

  • reason (String, nil) (defaults to: nil)

    The reason to show in the audit log for deleting the tag.

Returns:

  • (nil)


54
55
56
# File 'lib/discordrb/data/channel_tag.rb', line 54

def delete(reason: nil)
  @channel.update_tags({ id: @id, d: true }, reason)
end

#emojiEmoji?

Get the emoji of the channel tag.

Returns:

  • (Emoji, nil)

    the emoji of the channel tag, or nil if no emoji has been set.



31
32
33
# File 'lib/discordrb/data/channel_tag.rb', line 31

def emoji
  @emoji_id ? @channel.server.emojis[@emoji_id] : @emoji_name
end

#modify(name: :undef, emoji: :undef, moderated: :undef, reason: nil) ⇒ nil

Modify the properties of the channel tag.

Parameters:

  • name (String) (defaults to: :undef)

    The new 1-20 character name of the channel tag.

  • emoji (Emoji, Integer, String, nil) (defaults to: :undef)

    The new emoji of the channel tag.

  • moderated (true, false) (defaults to: :undef)

    Whether or not the channel tag should be moderated.

  • reason (String, nil) (defaults to: nil)

    The reason to show in the audit log for modifying the tag.

Returns:

  • (nil)


41
42
43
44
45
46
47
48
49
# File 'lib/discordrb/data/channel_tag.rb', line 41

def modify(name: :undef, emoji: :undef, moderated: :undef, reason: nil)
  data = {
    name: name,
    moderated: moderated,
    **(Emoji.build_emoji_hash(emoji) if emoji != :undef)
  }.reject { |_, value| value == :undef }

  @channel.update_tags(to_h.merge(data), reason)
end