Class: Discordrb::Channel

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

Overview

A Discord channel, including data like the topic

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idInteger (readonly) Also known as: resolve_id

Note:

If this channel is a #general channel, its ID will be equal to the server on which it is on.

Returns the channel's unique ID.



481
482
483
# File 'lib/discordrb/data.rb', line 481

def id
  @id
end

#is_privatetrue, false (readonly)

Deprecated.

Use #private? instead, it's guaranteed to be accurate.

Note:

This data is sent by Discord and it's possible for this to falsely be true for certain kinds of integration channels (like Twitch subscriber ones). This appears to be a Discord bug that I can't reproduce myself, due to not having any integrations in place. If this occurs to you please tell me.

Returns whether or not this channel is a private messaging channel.



488
489
490
# File 'lib/discordrb/data.rb', line 488

def is_private
  @is_private
end

#nameString



471
472
473
# File 'lib/discordrb/data.rb', line 471

def name
  @name
end

#permission_overwritesHash<Integer => OpenStruct> (readonly)

This channel's permission overwrites, represented as a hash of role/user ID to an OpenStruct which has the allow and deny properties which are Permissions objects respectively.



502
503
504
# File 'lib/discordrb/data.rb', line 502

def permission_overwrites
  @permission_overwrites
end

#positionInteger



497
498
499
# File 'lib/discordrb/data.rb', line 497

def position
  @position
end

#recipientUser? (readonly)



491
492
493
# File 'lib/discordrb/data.rb', line 491

def recipient
  @recipient
end

#serverServer (readonly)



474
475
476
# File 'lib/discordrb/data.rb', line 474

def server
  @server
end

#topicString



494
495
496
# File 'lib/discordrb/data.rb', line 494

def topic
  @topic
end

#typeString (readonly)



477
478
479
# File 'lib/discordrb/data.rb', line 477

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object

ID based comparison



547
548
549
# File 'lib/discordrb/data.rb', line 547

def ==(other)
  Discordrb.id_compare(@id, other)
end

#await(key, attributes = {}, &block) ⇒ Object

Add an Await for a message in this channel. This is identical in functionality to adding a Events::MessageEvent await with the in attribute as this channel.

See Also:



637
638
639
# File 'lib/discordrb/data.rb', line 637

def await(key, attributes = {}, &block)
  @bot.add_await(key, Discordrb::Events::MessageEvent, { in: @id }.merge(attributes), &block)
end

#deleteObject

Permanently deletes this channel



565
566
567
# File 'lib/discordrb/data.rb', line 565

def delete
  API.delete_channel(@bot.token, @id)
end

#history(amount, before_id = nil, after_id = nil) ⇒ Array<Message>

Retrieves some of this channel's message history.



622
623
624
625
# File 'lib/discordrb/data.rb', line 622

def history(amount, before_id = nil, after_id = nil)
  logs = API.channel_log(@bot.token, @id, amount, before_id, after_id)
  JSON.parse(logs).map { |message| Message.new(message, @bot) }
end

#make_invite(max_age = 0, max_uses = 0, temporary = false, xkcd = false) ⇒ Object Also known as: invite



641
642
643
644
# File 'lib/discordrb/data.rb', line 641

def make_invite(max_age = 0, max_uses = 0, temporary = false, xkcd = false)
  response = API.create_invite(@bot.token, @id, max_age, max_uses, temporary, xkcd)
  Invite.new(JSON.parse(response), @bot)
end

#private?true, false



507
508
509
# File 'lib/discordrb/data.rb', line 507

def private?
  @server.nil?
end

#send_file(file) ⇒ Object

Sends a file to this channel. If it is an image, it will be embedded.



560
561
562
# File 'lib/discordrb/data.rb', line 560

def send_file(file)
  @bot.send_file(@id, file)
end

#send_message(content) ⇒ Message Also known as: send, message

Sends a message to this channel.



554
555
556
# File 'lib/discordrb/data.rb', line 554

def send_message(content)
  @bot.send_message(@id, content)
end

#start_typingObject

Starts typing, which displays the typing indicator on the client for five seconds. If you want to keep typing you'll have to resend this every five seconds. (An abstraction for this will eventually be coming)



649
650
651
# File 'lib/discordrb/data.rb', line 649

def start_typing
  API.start_typing(@bot.token, @id)
end

#usersArray<User>

The list of users currently in this channel. This is mostly useful for a voice channel, for a text channel it will just return the users on the server that are online.



604
605
606
607
608
609
610
611
612
# File 'lib/discordrb/data.rb', line 604

def users
  if @type == 'text'
    @server.members.select { |u| u.status != :offline }
  else
    @server.members.select do |user|
      user.voice_channel.id == @id if user.voice_channel
    end
  end
end