module Discordrb::API::User
Public Instance Methods
Make an avatar URL from the user and avatar IDs
# File lib/discordrb/api/user.rb, line 147 def avatar_url(user_id, avatar_id, format = nil) format ||= if avatar_id.start_with?('a_') 'gif' else 'webp' end "#{Discordrb::API.cdn_url}/avatars/#{user_id}/#{avatar_id}.#{format}" end
Change the current bot’s nickname on a server discord.com/developers/docs/resources/user#modify-current-user
# File lib/discordrb/api/user.rb, line 33 def change_own_nickname(token, server_id, nick, reason = nil) Discordrb::API.request( :guilds_sid_members_me_nick, server_id, # This is technically a guild endpoint :patch, "#{Discordrb::API.api_base}/guilds/#{server_id}/members/@me/nick", { nick: nick }.to_json, Authorization: token, content_type: :json, 'X-Audit-Log-Reason': reason ) end
Change user status setting
# File lib/discordrb/api/user.rb, line 123 def change_status_setting(token, status) Discordrb::API.request( :users_me_settings, nil, :patch, "#{Discordrb::API.api_base}/users/@me/settings", { status: status }.to_json, Authorization: token, content_type: :json ) end
Get information about a user’s connections discord.com/developers/docs/resources/user#get-users-connections
# File lib/discordrb/api/user.rb, line 112 def connections(token) Discordrb::API.request( :users_me_connections, nil, :get, "#{Discordrb::API.api_base}/users/@me/connections", Authorization: token ) end
Create a DM to another user discord.com/developers/docs/resources/user#create-dm
# File lib/discordrb/api/user.rb, line 98 def create_pm(token, recipient_id) Discordrb::API.request( :users_me_channels, nil, :post, "#{Discordrb::API.api_base}/users/@me/channels", { recipient_id: recipient_id }.to_json, Authorization: token, content_type: :json ) end
Returns one of the “default” discord avatars from the CDN given a discriminator or id since new usernames TODO: Maybe change this method again after discriminator removal ?
# File lib/discordrb/api/user.rb, line 137 def default_avatar(discrim_id = 0, legacy: false) index = if legacy discrim_id.to_i % 5 else (discrim_id.to_i >> 22) % 5 end "#{Discordrb::API.cdn_url}/embed/avatars/#{index}.png" end
Leave a server discord.com/developers/docs/resources/user#leave-guild
# File lib/discordrb/api/user.rb, line 74 def leave_server(token, server_id) Discordrb::API.request( :users_me_guilds_sid, nil, :delete, "#{Discordrb::API.api_base}/users/@me/guilds/#{server_id}", Authorization: token ) end
Get profile data discord.com/developers/docs/resources/user#get-current-user
# File lib/discordrb/api/user.rb, line 21 def profile(token) Discordrb::API.request( :users_me, nil, :get, "#{Discordrb::API.api_base}/users/@me", Authorization: token ) end
Get user data discord.com/developers/docs/resources/user#get-user
# File lib/discordrb/api/user.rb, line 9 def resolve(token, user_id) Discordrb::API.request( :users_uid, nil, :get, "#{Discordrb::API.api_base}/users/#{user_id}", Authorization: token ) end
Get the servers a user is connected to discord.com/developers/docs/resources/user#get-current-user-guilds
# File lib/discordrb/api/user.rb, line 62 def servers(token) Discordrb::API.request( :users_me_guilds, nil, :get, "#{Discordrb::API.api_base}/users/@me/guilds", Authorization: token ) end
Update user data discord.com/developers/docs/resources/user#modify-current-user
# File lib/discordrb/api/user.rb, line 48 def update_profile(token, email, password, new_username, avatar, new_password = nil) Discordrb::API.request( :users_me, nil, :patch, "#{Discordrb::API.api_base}/users/@me", { avatar: avatar, email: email, new_password: new_password, password: password, username: new_username }.to_json, Authorization: token, content_type: :json ) end
Get the DMs for the current user discord.com/developers/docs/resources/user#get-user-dms
# File lib/discordrb/api/user.rb, line 86 def user_dms(token) Discordrb::API.request( :users_me_channels, nil, :get, "#{Discordrb::API.api_base}/users/@me/channels", Authorization: token ) end