module MijDiscord::Core::API::Channel

Public Class Methods

add_group_user(auth, group_channel_id, user_id) click to toggle source

Add a user to a group channel.

# File lib/mij-discord/core/api/channel.rb, line 348
def add_group_user(auth, group_channel_id, user_id)
  MijDiscord::Core::API.request(
    :channels_cid_recipients_uid,
    nil,
    :put,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{group_channel_id}/recipients/#{user_id}",
    {}.to_json,
    Authorization: auth,
    content_type: :json
  )
end
bulk_delete_messages(auth, channel_id, messages = []) click to toggle source

Delete messages in bulk discordapp.com/developers/docs/resources/channel#bulk-delete-messages

# File lib/mij-discord/core/api/channel.rb, line 129
def bulk_delete_messages(auth, channel_id, messages = [])
  MijDiscord::Core::API.request(
    :channels_cid_messages_bulk_delete,
    channel_id,
    :post,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/messages/bulk-delete",
    { messages: messages }.to_json,
    Authorization: auth,
    content_type: :json
  )
end
create_empty_group(auth, bot_user_id) click to toggle source

Create an empty group channel.

# File lib/mij-discord/core/api/channel.rb, line 316
def create_empty_group(auth, bot_user_id)
  MijDiscord::Core::API.request(
    :users_uid_channels,
    nil,
    :post,
    "#{MijDiscord::Core::API::APIBASE_URL}/users/#{bot_user_id}/channels",
    {}.to_json,
    Authorization: auth,
    content_type: :json
  )
end
create_group(auth, pm_channel_id, user_id) click to toggle source

Create a group channel.

# File lib/mij-discord/core/api/channel.rb, line 329
def create_group(auth, pm_channel_id, user_id)
  MijDiscord::Core::API.request(
    :channels_cid_recipients_uid,
    nil,
    :put,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{pm_channel_id}/recipients/#{user_id}",
    {}.to_json,
    Authorization: auth,
    content_type: :json
  )
rescue RestClient::InternalServerError
  raise 'Attempted to add self as a new group channel recipient!'
rescue RestClient::NoContent
  raise 'Attempted to create a group channel with the PM channel recipient!'
rescue RestClient::Forbidden
  raise 'Attempted to add a user to group channel without permission!'
end
create_invite(auth, channel_id, max_age = 0, max_uses = 0, temporary = false, unique = false, reason = nil) click to toggle source

Create an instant invite from a server or a channel id discordapp.com/developers/docs/resources/channel#create-channel-invite

# File lib/mij-discord/core/api/channel.rb, line 239
def create_invite(auth, channel_id, max_age = 0, max_uses = 0, temporary = false, unique = false, reason = nil)
  MijDiscord::Core::API.request(
    :channels_cid_invites,
    channel_id,
    :post,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/invites",
    { max_age: max_age, max_uses: max_uses, temporary: temporary, unique: unique }.to_json,
    Authorization: auth,
    content_type: :json,
    'X-Audit-Log-Reason': reason
  )
end
create_message(auth, channel_id, message, tts = false, embed = nil, mentions = []) click to toggle source

Send a message to a channel discordapp.com/developers/docs/resources/channel#create-message

# File lib/mij-discord/core/api/channel.rb, line 76
def create_message(auth, channel_id, message, tts = false, embed = nil, mentions = [])
  MijDiscord::Core::API.request(
    :channels_cid_messages_mid,
    channel_id,
    :post,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/messages",
    { content: message, mentions: mentions, tts: tts, embed: embed }.to_json,
    Authorization: auth,
    content_type: :json
  )
end
create_reaction(auth, channel_id, message_id, emoji) click to toggle source

Create a reaction on a message using this client discordapp.com/developers/docs/resources/channel#create-reaction

# File lib/mij-discord/core/api/channel.rb, line 143
def create_reaction(auth, channel_id, message_id, emoji)
  emoji = URI.encode(emoji) unless emoji.ascii_only?
  MijDiscord::Core::API.request(
    :channels_cid_messages_mid_reactions_emoji_me,
    channel_id,
    :put,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}/@me",
    nil,
    Authorization: auth,
    content_type: :json,
    header_bypass_delay: 0.25
  )
end
create_webhook(auth, channel_id, name, avatar = nil, reason = nil) click to toggle source

Create a webhook discordapp.com/developers/docs/resources/webhook#create-webhook

# File lib/mij-discord/core/api/channel.rb, line 386
def create_webhook(auth, channel_id, name, avatar = nil, reason = nil)
  MijDiscord::Core::API.request(
    :channels_cid_webhooks,
    channel_id,
    :post,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/webhooks",
    { name: name, avatar: avatar }.to_json,
    Authorization: auth,
    content_type: :json,
    'X-Audit-Log-Reason': reason
  )
end
delete(auth, channel_id, reason = nil) click to toggle source

Delete a channel discordapp.com/developers/docs/resources/channel#deleteclose-channel

# File lib/mij-discord/core/api/channel.rb, line 39
def delete(auth, channel_id, reason = nil)
  MijDiscord::Core::API.request(
    :channels_cid,
    channel_id,
    :delete,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}",
    Authorization: auth,
    'X-Audit-Log-Reason': reason
  )
end
delete_all_reactions(auth, channel_id, message_id) click to toggle source

Deletes all reactions on a message from all clients discordapp.com/developers/docs/resources/channel#delete-all-reactions

# File lib/mij-discord/core/api/channel.rb, line 200
def delete_all_reactions(auth, channel_id, message_id)
  MijDiscord::Core::API.request(
    :channels_cid_messages_mid_reactions,
    channel_id,
    :delete,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/messages/#{message_id}/reactions",
    Authorization: auth
  )
end
delete_message(auth, channel_id, message_id) click to toggle source

Delete a message discordapp.com/developers/docs/resources/channel#delete-message

# File lib/mij-discord/core/api/channel.rb, line 117
def delete_message(auth, channel_id, message_id)
  MijDiscord::Core::API.request(
    :channels_cid_messages_mid,
    channel_id,
    :delete,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/messages/#{message_id}",
    Authorization: auth
  )
end
delete_own_reaction(auth, channel_id, message_id, emoji) click to toggle source

Delete this client's own reaction on a message discordapp.com/developers/docs/resources/channel#delete-own-reaction

# File lib/mij-discord/core/api/channel.rb, line 159
def delete_own_reaction(auth, channel_id, message_id, emoji)
  emoji = URI.encode(emoji) unless emoji.ascii_only?
  MijDiscord::Core::API.request(
    :channels_cid_messages_mid_reactions_emoji_me,
    channel_id,
    :delete,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}/@me",
    Authorization: auth,
    header_bypass_delay: 0.25
  )
end
delete_permission(auth, channel_id, overwrite_id, reason = nil) click to toggle source

Delete channel permission discordapp.com/developers/docs/resources/channel#delete-channel-permission

# File lib/mij-discord/core/api/channel.rb, line 254
def delete_permission(auth, channel_id, overwrite_id, reason = nil)
  MijDiscord::Core::API.request(
    :channels_cid_permissions_oid,
    channel_id,
    :delete,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/permissions/#{overwrite_id}",
    Authorization: auth,
    'X-Audit-Log-Reason': reason
  )
end
delete_user_reaction(auth, channel_id, message_id, emoji, user_id) click to toggle source

Delete another client's reaction on a message discordapp.com/developers/docs/resources/channel#delete-user-reaction

# File lib/mij-discord/core/api/channel.rb, line 173
def delete_user_reaction(auth, channel_id, message_id, emoji, user_id)
  emoji = URI.encode(emoji) unless emoji.ascii_only?
  MijDiscord::Core::API.request(
    :channels_cid_messages_mid_reactions_emoji_uid,
    channel_id,
    :delete,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}/#{user_id}",
    Authorization: auth,
    header_bypass_delay: 0.25
  )
end
edit_message(auth, channel_id, message_id, message, mentions = [], embed = nil) click to toggle source

Edit a message discordapp.com/developers/docs/resources/channel#edit-message

# File lib/mij-discord/core/api/channel.rb, line 103
def edit_message(auth, channel_id, message_id, message, mentions = [], embed = nil)
  MijDiscord::Core::API.request(
    :channels_cid_messages_mid,
    channel_id,
    :patch,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/messages/#{message_id}",
    { content: message, mentions: mentions, embed: embed }.to_json,
    Authorization: auth,
    content_type: :json
  )
end
get_reactions(auth, channel_id, message_id, emoji) click to toggle source

Get a list of clients who reacted with a specific reaction on a message discordapp.com/developers/docs/resources/channel#get-reactions

# File lib/mij-discord/core/api/channel.rb, line 187
def get_reactions(auth, channel_id, message_id, emoji)
  emoji = URI.encode(emoji) unless emoji.ascii_only?
  MijDiscord::Core::API.request(
    :channels_cid_messages_mid_reactions_emoji,
    channel_id,
    :get,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}",
    Authorization: auth
  )
end
invites(auth, channel_id) click to toggle source

Get a channel's invite list discordapp.com/developers/docs/resources/channel#get-channel-invites

# File lib/mij-discord/core/api/channel.rb, line 227
def invites(auth, channel_id)
  MijDiscord::Core::API.request(
    :channels_cid_invites,
    channel_id,
    :get,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/invites",
    Authorization: auth
  )
end
leave_group(auth, group_channel_id) click to toggle source

Leave a group channel.

# File lib/mij-discord/core/api/channel.rb, line 373
def leave_group(auth, group_channel_id)
  MijDiscord::Core::API.request(
    :channels_cid,
    nil,
    :delete,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{group_channel_id}",
    Authorization: auth,
    content_type: :json
  )
end
message(auth, channel_id, message_id) click to toggle source

Get a single message from a channel's history by id discordapp.com/developers/docs/resources/channel#get-channel-message

# File lib/mij-discord/core/api/channel.rb, line 64
def message(auth, channel_id, message_id)
  MijDiscord::Core::API.request(
    :channels_cid_messages_mid,
    channel_id,
    :get,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/messages/#{message_id}",
    Authorization: auth
  )
end
messages(auth, channel_id, amount, before = nil, after = nil, around = nil) click to toggle source

Get a list of messages from a channel's history discordapp.com/developers/docs/resources/channel#get-channel-messages

# File lib/mij-discord/core/api/channel.rb, line 52
def messages(auth, channel_id, amount, before = nil, after = nil, around = nil)
  MijDiscord::Core::API.request(
    :channels_cid_messages,
    channel_id,
    :get,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/messages?limit=#{amount}#{"&before=#{before}" if before}#{"&after=#{after}" if after}#{"&around=#{around}" if around}",
    Authorization: auth
  )
end
pin_message(auth, channel_id, message_id) click to toggle source

Pin a message discordapp.com/developers/docs/resources/channel#add-pinned-channel-message

# File lib/mij-discord/core/api/channel.rb, line 292
def pin_message(auth, channel_id, message_id)
  MijDiscord::Core::API.request(
    :channels_cid_pins_mid,
    channel_id,
    :put,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/pins/#{message_id}",
    nil,
    Authorization: auth
  )
end
pinned_messages(auth, channel_id) click to toggle source

Get a list of pinned messages in a channel discordapp.com/developers/docs/resources/channel#get-pinned-messages

# File lib/mij-discord/core/api/channel.rb, line 280
def pinned_messages(auth, channel_id)
  MijDiscord::Core::API.request(
    :channels_cid_pins,
    channel_id,
    :get,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/pins",
    Authorization: auth
  )
end
remove_group_user(auth, group_channel_id, user_id) click to toggle source

Remove a user from a group channel.

# File lib/mij-discord/core/api/channel.rb, line 361
def remove_group_user(auth, group_channel_id, user_id)
  MijDiscord::Core::API.request(
    :channels_cid_recipients_uid,
    nil,
    :delete,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{group_channel_id}/recipients/#{user_id}",
    Authorization: auth,
    content_type: :json
  )
end
resolve(auth, channel_id) click to toggle source

Get a channel's data discordapp.com/developers/docs/resources/channel#get-channel

# File lib/mij-discord/core/api/channel.rb, line 7
def resolve(auth, channel_id)
  MijDiscord::Core::API.request(
    :channels_cid,
    channel_id,
    :get,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}",
    Authorization: auth
  )
end
start_typing(auth, channel_id) click to toggle source

Start typing (needs to be resent every 5 seconds to keep up the typing) discordapp.com/developers/docs/resources/channel#trigger-typing-indicator

# File lib/mij-discord/core/api/channel.rb, line 267
def start_typing(auth, channel_id)
  MijDiscord::Core::API.request(
    :channels_cid_typing,
    channel_id,
    :post,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/typing",
    nil,
    Authorization: auth
  )
end
unpin_message(auth, channel_id, message_id) click to toggle source

Unpin a message discordapp.com/developers/docs/resources/channel#delete-pinned-channel-message

# File lib/mij-discord/core/api/channel.rb, line 305
def unpin_message(auth, channel_id, message_id)
  MijDiscord::Core::API.request(
    :channels_cid_pins_mid,
    channel_id,
    :delete,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/pins/#{message_id}",
    Authorization: auth
  )
end
update(auth, channel_id, name, topic, nsfw, parent_id, position, bitrate, user_limit, overwrites, reason = nil) click to toggle source

Update a channel's data discordapp.com/developers/docs/resources/channel#modify-channel

# File lib/mij-discord/core/api/channel.rb, line 19
def update(auth, channel_id, name, topic, nsfw, parent_id, position, bitrate, user_limit, overwrites, reason = nil)
  MijDiscord::Core::API.request(
    :channels_cid,
    channel_id,
    :patch,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}",
    {
      name: name, topic: topic, nsfw: nsfw,
      parent_id: parent_id, position: position,
      bitrate: bitrate, user_limit: user_limit,
      permission_overwrites: overwrites
    }.delete_if {|_, v| v.nil? }.to_json,
    Authorization: auth,
    content_type: :json,
    'X-Audit-Log-Reason': reason
  )
end
update_permission(auth, channel_id, overwrite_id, allow, deny, type, reason = nil) click to toggle source

Update a channels permission for a role or member discordapp.com/developers/docs/resources/channel#edit-channel-permissions

# File lib/mij-discord/core/api/channel.rb, line 212
def update_permission(auth, channel_id, overwrite_id, allow, deny, type, reason = nil)
  MijDiscord::Core::API.request(
    :channels_cid_permissions_oid,
    channel_id,
    :put,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/permissions/#{overwrite_id}",
    { type: type, id: overwrite_id, allow: allow, deny: deny }.to_json,
    Authorization: auth,
    content_type: :json,
    'X-Audit-Log-Reason': reason
  )
end
upload_file(auth, channel_id, file, caption = nil, tts = false) click to toggle source

Send a file as a message to a channel discordapp.com/developers/docs/resources/channel#upload-file

# File lib/mij-discord/core/api/channel.rb, line 90
def upload_file(auth, channel_id, file, caption = nil, tts = false)
  MijDiscord::Core::API.request(
    :channels_cid_messages_mid,
    channel_id,
    :post,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/messages",
    { file: file, content: caption, tts: tts },
    Authorization: auth
  )
end
webhooks(auth, channel_id) click to toggle source

Get channel webhooks discordapp.com/developers/docs/resources/webhook#get-channel-webhooks

# File lib/mij-discord/core/api/channel.rb, line 401
def webhooks(auth, channel_id)
  MijDiscord::Core::API.request(
    :channels_cid_webhooks,
    channel_id,
    :get,
    "#{MijDiscord::Core::API::APIBASE_URL}/channels/#{channel_id}/webhooks",
    Authorization: auth
  )
end