module Discordrb::API::Channel
Public Instance Methods
Add a user to a group channel.
# File lib/discordrb/api/channel.rb, line 349 def add_group_user(token, group_channel_id, user_id) Discordrb::API.request( :channels_cid_recipients_uid, nil, :put, "#{Discordrb::API.api_base}/channels/#{group_channel_id}/recipients/#{user_id}", {}.to_json, Authorization: token, content_type: :json ) end
Delete messages in bulk discordapp.com/developers/docs/resources/channel#bulk-delete-messages
# File lib/discordrb/api/channel.rb, line 133 def bulk_delete_messages(token, channel_id, messages = []) Discordrb::API.request( :channels_cid_messages_bulk_delete, channel_id, :post, "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/bulk-delete", { messages: messages }.to_json, Authorization: token, content_type: :json ) end
Create an empty group channel.
# File lib/discordrb/api/channel.rb, line 317 def create_empty_group(token, bot_user_id) Discordrb::API.request( :users_uid_channels, nil, :post, "#{Discordrb::API.api_base}/users/#{bot_user_id}/channels", {}.to_json, Authorization: token, content_type: :json ) end
Create a group channel.
# File lib/discordrb/api/channel.rb, line 330 def create_group(token, pm_channel_id, user_id) Discordrb::API.request( :channels_cid_recipients_uid, nil, :put, "#{Discordrb::API.api_base}/channels/#{pm_channel_id}/recipients/#{user_id}", {}.to_json, Authorization: token, 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 an instant invite from a server or a channel id discordapp.com/developers/docs/resources/channel#create-channel-invite
# File lib/discordrb/api/channel.rb, line 240 def create_invite(token, channel_id, max_age = 0, max_uses = 0, temporary = false, unique = false, reason = nil) Discordrb::API.request( :channels_cid_invites, channel_id, :post, "#{Discordrb::API.api_base}/channels/#{channel_id}/invites", { max_age: max_age, max_uses: max_uses, temporary: temporary, unique: unique }.to_json, Authorization: token, content_type: :json, 'X-Audit-Log-Reason': reason ) end
Send a message to a channel discordapp.com/developers/docs/resources/channel#create-message
# File lib/discordrb/api/channel.rb, line 75 def create_message(token, channel_id, message, tts = false, embed = nil, nonce = nil) Discordrb::API.request( :channels_cid_messages_mid, channel_id, :post, "#{Discordrb::API.api_base}/channels/#{channel_id}/messages", { content: message, tts: tts, embed: embed, nonce: nonce }.to_json, Authorization: token, content_type: :json ) rescue RestClient::BadRequest => e parsed = JSON.parse(e.response.body) raise Discordrb::Errors::MessageTooLong, "Message over the character limit (#{message.length} > 2000)" if parsed['content']&.is_a?(Array) && parsed['content'].first == 'Must be 2000 or fewer in length.' raise end
Create a reaction on a message using this client discordapp.com/developers/docs/resources/channel#create-reaction
# File lib/discordrb/api/channel.rb, line 147 def create_reaction(token, channel_id, message_id, emoji) emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only? Discordrb::API.request( :channels_cid_messages_mid_reactions_emoji_me, channel_id, :put, "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}/@me", nil, Authorization: token, content_type: :json ) end
Create a webhook discordapp.com/developers/docs/resources/webhook#create-webhook
# File lib/discordrb/api/channel.rb, line 387 def create_webhook(token, channel_id, name, avatar = nil, reason = nil) Discordrb::API.request( :channels_cid_webhooks, channel_id, :post, "#{Discordrb::API.api_base}/channels/#{channel_id}/webhooks", { name: name, avatar: avatar }.to_json, Authorization: token, content_type: :json, 'X-Audit-Log-Reason': reason ) end
Delete a channel discordapp.com/developers/docs/resources/channel#deleteclose-channel
# File lib/discordrb/api/channel.rb, line 38 def delete(token, channel_id, reason = nil) Discordrb::API.request( :channels_cid, channel_id, :delete, "#{Discordrb::API.api_base}/channels/#{channel_id}", Authorization: token, 'X-Audit-Log-Reason': reason ) end
Deletes all reactions on a message from all clients discordapp.com/developers/docs/resources/channel#delete-all-reactions
# File lib/discordrb/api/channel.rb, line 201 def delete_all_reactions(token, channel_id, message_id) Discordrb::API.request( :channels_cid_messages_mid_reactions, channel_id, :delete, "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions", Authorization: token ) end
Delete a message discordapp.com/developers/docs/resources/channel#delete-message
# File lib/discordrb/api/channel.rb, line 121 def delete_message(token, channel_id, message_id) Discordrb::API.request( :channels_cid_messages_mid, channel_id, :delete, "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}", Authorization: token ) end
Delete this client's own reaction on a message discordapp.com/developers/docs/resources/channel#delete-own-reaction
# File lib/discordrb/api/channel.rb, line 162 def delete_own_reaction(token, channel_id, message_id, emoji) emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only? Discordrb::API.request( :channels_cid_messages_mid_reactions_emoji_me, channel_id, :delete, "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}/@me", Authorization: token ) end
Delete channel permission discordapp.com/developers/docs/resources/channel#delete-channel-permission
# File lib/discordrb/api/channel.rb, line 255 def delete_permission(token, channel_id, overwrite_id, reason = nil) Discordrb::API.request( :channels_cid_permissions_oid, channel_id, :delete, "#{Discordrb::API.api_base}/channels/#{channel_id}/permissions/#{overwrite_id}", Authorization: token, 'X-Audit-Log-Reason': reason ) end
Delete another client's reaction on a message discordapp.com/developers/docs/resources/channel#delete-user-reaction
# File lib/discordrb/api/channel.rb, line 175 def delete_user_reaction(token, channel_id, message_id, emoji, user_id) emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only? Discordrb::API.request( :channels_cid_messages_mid_reactions_emoji_uid, channel_id, :delete, "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}/#{user_id}", Authorization: token ) end
Edit a message discordapp.com/developers/docs/resources/channel#edit-message
# File lib/discordrb/api/channel.rb, line 107 def edit_message(token, channel_id, message_id, message, mentions = [], embed = nil) Discordrb::API.request( :channels_cid_messages_mid, channel_id, :patch, "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}", { content: message, mentions: mentions, embed: embed }.to_json, Authorization: token, content_type: :json ) end
Get a list of clients who reacted with a specific reaction on a message discordapp.com/developers/docs/resources/channel#get-reactions
# File lib/discordrb/api/channel.rb, line 188 def get_reactions(token, channel_id, message_id, emoji) emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only? Discordrb::API.request( :channels_cid_messages_mid_reactions_emoji, channel_id, :get, "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}", Authorization: token ) end
Get a channel's invite list discordapp.com/developers/docs/resources/channel#get-channel-invites
# File lib/discordrb/api/channel.rb, line 228 def invites(token, channel_id) Discordrb::API.request( :channels_cid_invites, channel_id, :get, "#{Discordrb::API.api_base}/channels/#{channel_id}/invites", Authorization: token ) end
Leave a group channel.
# File lib/discordrb/api/channel.rb, line 374 def leave_group(token, group_channel_id) Discordrb::API.request( :channels_cid, nil, :delete, "#{Discordrb::API.api_base}/channels/#{group_channel_id}", Authorization: token, content_type: :json ) end
Get a single message from a channel's history by id discordapp.com/developers/docs/resources/channel#get-channel-message
# File lib/discordrb/api/channel.rb, line 63 def message(token, channel_id, message_id) Discordrb::API.request( :channels_cid_messages_mid, channel_id, :get, "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}", Authorization: token ) end
Get a list of messages from a channel's history discordapp.com/developers/docs/resources/channel#get-channel-messages
# File lib/discordrb/api/channel.rb, line 51 def messages(token, channel_id, amount, before = nil, after = nil, around = nil) Discordrb::API.request( :channels_cid_messages, channel_id, :get, "#{Discordrb::API.api_base}/channels/#{channel_id}/messages?limit=#{amount}#{"&before=#{before}" if before}#{"&after=#{after}" if after}#{"&around=#{around}" if around}", Authorization: token ) end
Pin a message discordapp.com/developers/docs/resources/channel#add-pinned-channel-message
# File lib/discordrb/api/channel.rb, line 293 def pin_message(token, channel_id, message_id) Discordrb::API.request( :channels_cid_pins_mid, channel_id, :put, "#{Discordrb::API.api_base}/channels/#{channel_id}/pins/#{message_id}", nil, Authorization: token ) end
Get a list of pinned messages in a channel discordapp.com/developers/docs/resources/channel#get-pinned-messages
# File lib/discordrb/api/channel.rb, line 281 def pinned_messages(token, channel_id) Discordrb::API.request( :channels_cid_pins, channel_id, :get, "#{Discordrb::API.api_base}/channels/#{channel_id}/pins", Authorization: token ) end
Remove a user from a group channel.
# File lib/discordrb/api/channel.rb, line 362 def remove_group_user(token, group_channel_id, user_id) Discordrb::API.request( :channels_cid_recipients_uid, nil, :delete, "#{Discordrb::API.api_base}/channels/#{group_channel_id}/recipients/#{user_id}", Authorization: token, content_type: :json ) end
Get a channel's data discordapp.com/developers/docs/resources/channel#get-channel
# File lib/discordrb/api/channel.rb, line 9 def resolve(token, channel_id) Discordrb::API.request( :channels_cid, channel_id, :get, "#{Discordrb::API.api_base}/channels/#{channel_id}", Authorization: token ) end
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/discordrb/api/channel.rb, line 268 def start_typing(token, channel_id) Discordrb::API.request( :channels_cid_typing, channel_id, :post, "#{Discordrb::API.api_base}/channels/#{channel_id}/typing", nil, Authorization: token ) end
Unpin a message discordapp.com/developers/docs/resources/channel#delete-pinned-channel-message
# File lib/discordrb/api/channel.rb, line 306 def unpin_message(token, channel_id, message_id) Discordrb::API.request( :channels_cid_pins_mid, channel_id, :delete, "#{Discordrb::API.api_base}/channels/#{channel_id}/pins/#{message_id}", Authorization: token ) end
Update a channel's data discordapp.com/developers/docs/resources/channel#modify-channel
# File lib/discordrb/api/channel.rb, line 21 def update(token, channel_id, name, topic, position, bitrate, user_limit, nsfw, permission_overwrites = nil, parent_id = nil, rate_limit_per_user = nil, reason = nil) data = { name: name, position: position, topic: topic, bitrate: bitrate, user_limit: user_limit, nsfw: nsfw, parent_id: parent_id, rate_limit_per_user: rate_limit_per_user } data[:permission_overwrites] = permission_overwrites unless permission_overwrites.nil? Discordrb::API.request( :channels_cid, channel_id, :patch, "#{Discordrb::API.api_base}/channels/#{channel_id}", data.to_json, Authorization: token, content_type: :json, 'X-Audit-Log-Reason': reason ) end
Update a channels permission for a role or member discordapp.com/developers/docs/resources/channel#edit-channel-permissions
# File lib/discordrb/api/channel.rb, line 213 def update_permission(token, channel_id, overwrite_id, allow, deny, type, reason = nil) Discordrb::API.request( :channels_cid_permissions_oid, channel_id, :put, "#{Discordrb::API.api_base}/channels/#{channel_id}/permissions/#{overwrite_id}", { type: type, id: overwrite_id, allow: allow, deny: deny }.to_json, Authorization: token, content_type: :json, 'X-Audit-Log-Reason': reason ) end
Send a file as a message to a channel discordapp.com/developers/docs/resources/channel#upload-file
# File lib/discordrb/api/channel.rb, line 94 def upload_file(token, channel_id, file, caption: nil, tts: false) Discordrb::API.request( :channels_cid_messages_mid, channel_id, :post, "#{Discordrb::API.api_base}/channels/#{channel_id}/messages", { file: file, content: caption, tts: tts }, Authorization: token ) end
Get channel webhooks discordapp.com/developers/docs/resources/webhook#get-channel-webhooks
# File lib/discordrb/api/channel.rb, line 402 def webhooks(token, channel_id) Discordrb::API.request( :channels_cid_webhooks, channel_id, :get, "#{Discordrb::API.api_base}/channels/#{channel_id}/webhooks", Authorization: token ) end