discorb 0.5.5 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/discorb/guild.rb CHANGED
@@ -175,7 +175,7 @@ module Discorb
175
175
  # @macro http
176
176
  # @note This querys the API every time. We recommend using {#emojis} instead.
177
177
  #
178
- # @return [Discorb::Dictionary{Discorb::Snowflake => Discorb::CustomEmoji}] A dictionary of emoji in the guild.
178
+ # @return [Async::Task<Discorb::Dictionary{Discorb::Snowflake => Discorb::CustomEmoji}>] A dictionary of emoji in the guild.
179
179
  #
180
180
  def fetch_emoji_list
181
181
  Async do
@@ -201,7 +201,7 @@ module Discorb
201
201
  #
202
202
  # @param [#to_s] id The emoji id.
203
203
  #
204
- # @return [Discorb::CustomEmoji] The emoji with the given id.
204
+ # @return [Async::Task<Discorb::CustomEmoji>] The emoji with the given id.
205
205
  #
206
206
  def fetch_emoji(id)
207
207
  _resp, data = @client.http.get("/guilds/#{@id}/emojis/#{id}").wait
@@ -217,7 +217,7 @@ module Discorb
217
217
  # @param [Discorb::Image] image The image of the emoji.
218
218
  # @param [Array<Discorb::Role>] roles A list of roles to give the emoji.
219
219
  #
220
- # @return [Discorb::CustomEmoji] The created emoji.
220
+ # @return [Async::Task<Discorb::CustomEmoji>] The created emoji.
221
221
  #
222
222
  def create_emoji(name, image, roles: [])
223
223
  _resp, data = @client.http.post(
@@ -236,7 +236,7 @@ module Discorb
236
236
  # @macro async
237
237
  # @macro http
238
238
  #
239
- # @return [Array<Discorb::Webhook>] A list of webhooks in the guild.
239
+ # @return [Async::Task<Array<Discorb::Webhook>>] A list of webhooks in the guild.
240
240
  #
241
241
  def fetch_webhooks
242
242
  Async do
@@ -250,7 +250,7 @@ module Discorb
250
250
  # @macro async
251
251
  # @macro http
252
252
  #
253
- # @return [Discorb::AuditLog] The audit log of the guild.
253
+ # @return [Async::Task<Discorb::AuditLog>] The audit log of the guild.
254
254
  #
255
255
  def fetch_audit_log
256
256
  Async do
@@ -264,7 +264,7 @@ module Discorb
264
264
  # @macro async
265
265
  # @macro http
266
266
  #
267
- # @return [Array<Discorb::Channel>] A list of channels in the guild.
267
+ # @return [Async::Task<Array<Discorb::Channel>>] A list of channels in the guild.
268
268
  #
269
269
  def fetch_channels
270
270
  Async do
@@ -288,7 +288,7 @@ module Discorb
288
288
  # @param [Discorb::CategoryChannel] parent The parent of the channel.
289
289
  # @param [String] reason The reason for creating the channel.
290
290
  #
291
- # @return [Discorb::TextChannel] The created text channel.
291
+ # @return [Async::Task<Discorb::TextChannel>] The created text channel.
292
292
  #
293
293
  def create_text_channel(
294
294
  name, topic: nil, rate_limit_per_user: nil, slowmode: nil, position: nil, nsfw: nil, permission_overwrites: nil, parent: nil, reason: nil
@@ -333,7 +333,7 @@ module Discorb
333
333
  # @param [Discorb::CategoryChannel] parent The parent of the channel.
334
334
  # @param [String] reason The reason for creating the channel.
335
335
  #
336
- # @return [Discorb::VoiceChannel] The created voice channel.
336
+ # @return [Async::Task<Discorb::VoiceChannel>] The created voice channel.
337
337
  #
338
338
  def create_voice_channel(
339
339
  name, bitrate: 64, user_limit: nil, position: nil, permission_overwrites: nil, parent: nil, reason: nil
@@ -373,7 +373,7 @@ module Discorb
373
373
  # @param [Discorb::CategoryChannel] parent The parent of the channel.
374
374
  # @param [String] reason The reason for creating the channel.
375
375
  #
376
- # @return [Discorb::CategoryChannel] The created category channel.
376
+ # @return [Async::Task<Discorb::CategoryChannel>] The created category channel.
377
377
  #
378
378
  def create_category_channel(name, position: nil, permission_overwrites: nil, parent: nil, reason: nil)
379
379
  Async do
@@ -412,7 +412,7 @@ module Discorb
412
412
  # @param [Discorb::CategoryChannel] parent The parent of the channel.
413
413
  # @param [String] reason The reason for creating the channel.
414
414
  #
415
- # @return [Discorb::StageChannel] The created stage channel.
415
+ # @return [Async::Task<Discorb::StageChannel>] The created stage channel.
416
416
  #
417
417
  def create_stage_channel(name, bitrate: 64, position: nil, permission_overwrites: nil, parent: nil, reason: nil)
418
418
  Async do
@@ -453,7 +453,7 @@ module Discorb
453
453
  # @param [Discorb::CategoryChannel] parent The parent of the channel.
454
454
  # @param [String] reason The reason for creating the channel.
455
455
  #
456
- # @return [Discorb::NewsChannel] The created news channel.
456
+ # @return [Async::Task<Discorb::NewsChannel>] The created news channel.
457
457
  #
458
458
  def create_news_channel(
459
459
  name, topic: nil, rate_limit_per_user: nil, slowmode: nil, position: nil, nsfw: nil, permission_overwrites: nil, parent: nil, reason: nil
@@ -489,7 +489,7 @@ module Discorb
489
489
  # @macro async
490
490
  # @macro http
491
491
  #
492
- # @return [Array<Discorb::ThreadChannel>] The list of threads.
492
+ # @return [Async::Task<Array<Discorb::ThreadChannel>>] The list of threads.
493
493
  #
494
494
  def fetch_active_threads
495
495
  Async do
@@ -506,8 +506,8 @@ module Discorb
506
506
  #
507
507
  # @param [#to_s] id The ID of the member to fetch.
508
508
  #
509
- # @return [Discorb::Member] The member.
510
- # @return [nil] If the member is not found.
509
+ # @return [Async::Task<Discorb::Member>] The member.
510
+ # @return [Async::Task<nil>] If the member is not found.
511
511
  #
512
512
  def fetch_member(id)
513
513
  Async do
@@ -527,7 +527,7 @@ module Discorb
527
527
  # @param [String] name The name of the member to search for.
528
528
  # @param [Integer] limit The maximum number of members to return.
529
529
  #
530
- # @return [Array<Discorb::Member>] The list of members.
530
+ # @return [Async::Task<Array<Discorb::Member>>] The list of members.
531
531
  #
532
532
  def fetch_members_named(name, limit: 1)
533
533
  Async do
@@ -541,8 +541,8 @@ module Discorb
541
541
  # @macro async
542
542
  # @macro http
543
543
  #
544
- # @return [Discorb::Member] The member.
545
- # @return [nil] If the member is not found.
544
+ # @return [Async::Task<Discorb::Member>] The member.
545
+ # @return [Async::Task<nil>] If the member is not found.
546
546
  #
547
547
  def fetch_member_named(...)
548
548
  Async do
@@ -585,7 +585,7 @@ module Discorb
585
585
  # @macro async
586
586
  # @macro http
587
587
  #
588
- # @return [Array<Discorb::Guild::Ban>] The list of bans.
588
+ # @return [Async::Task<Array<Discorb::Guild::Ban>>] The list of bans.
589
589
  #
590
590
  def fetch_bans
591
591
  Async do
@@ -601,8 +601,8 @@ module Discorb
601
601
  #
602
602
  # @param [Discorb::User] user The user to fetch.
603
603
  #
604
- # @return [Discorb::Guild::Ban] The ban.
605
- # @return [nil] If the ban is not found.
604
+ # @return [Async::Task<Discorb::Guild::Ban>] The ban.
605
+ # @return [Async::Task<nil>] If the ban is not found.
606
606
  #
607
607
  def fetch_ban(user)
608
608
  Async do
@@ -621,7 +621,7 @@ module Discorb
621
621
  #
622
622
  # @param [Discorb::User] user The user to check.
623
623
  #
624
- # @return [Boolean] Whether the user was banned.
624
+ # @return [Async::Task<Boolean>] Whether the user was banned.
625
625
  #
626
626
  def banned?(user)
627
627
  Async do
@@ -638,7 +638,7 @@ module Discorb
638
638
  # @param [Integer] delete_message_days The number of days to delete messages.
639
639
  # @param [String] reason The reason for banning the member.
640
640
  #
641
- # @return [Discorb::Guild::Ban] The ban.
641
+ # @return [Async::Task<Discorb::Guild::Ban>] The ban.
642
642
  #
643
643
  def ban_member(member, delete_message_days: 0, reason: nil)
644
644
  Async do
@@ -668,7 +668,7 @@ module Discorb
668
668
  # @macro async
669
669
  # @macro http
670
670
  #
671
- # @return [Array<Discorb::Role>] The list of roles.
671
+ # @return [Async::Task<Array<Discorb::Role>>] The list of roles.
672
672
  #
673
673
  def fetch_roles
674
674
  Async do
@@ -688,7 +688,7 @@ module Discorb
688
688
  # @param [Boolean] mentionable Whether the role should be mentionable.
689
689
  # @param [String] reason The reason for creating the role.
690
690
  #
691
- # @return [Discorb::Role] The role.
691
+ # @return [Async::Task<Discorb::Role>] The role.
692
692
  #
693
693
  def create_role(name = nil, color: nil, hoist: nil, mentionable: nil, reason: nil)
694
694
  Async do
@@ -712,7 +712,7 @@ module Discorb
712
712
  # @param [Integer] days The number of days to prune.
713
713
  # @param [Array<Discorb::Role>] roles The roles that include for pruning.
714
714
  #
715
- # @return [Integer] The number of members that will be pruned.
715
+ # @return [Async::Task<Integer>] The number of members that will be pruned.
716
716
  #
717
717
  def fetch_prune(days = 7, roles: [])
718
718
  Async do
@@ -735,7 +735,7 @@ module Discorb
735
735
  # @param [Array<Discorb::Role>] roles The roles that include for pruning.
736
736
  # @param [String] reason The reason for pruning.
737
737
  #
738
- # @return [Integer] The number of members that were pruned.
738
+ # @return [Async::Task<Integer>] The number of members that were pruned.
739
739
  #
740
740
  def prune(days = 7, roles: [], reason: nil)
741
741
  Async do
@@ -751,7 +751,7 @@ module Discorb
751
751
  # @macro async
752
752
  # @macro http
753
753
  #
754
- # @return [Array<Discorb::VoiceRegion>] The available voice regions.
754
+ # @return [Async::Task<Array<Discorb::VoiceRegion>>] The available voice regions.
755
755
  #
756
756
  def fetch_voice_regions
757
757
  Async do
@@ -765,7 +765,7 @@ module Discorb
765
765
  # @macro async
766
766
  # @macro http
767
767
  #
768
- # @return [Array<Invite>] The invites.
768
+ # @return [Async::Task<Array<Invite>>] The invites.
769
769
  #
770
770
  def fetch_invites
771
771
  Async do
@@ -779,7 +779,7 @@ module Discorb
779
779
  # @macro async
780
780
  # @macro http
781
781
  #
782
- # @return [Array<Discorb::Integration>] The integrations.
782
+ # @return [Async::Task<Array<Discorb::Integration>>] The integrations.
783
783
  #
784
784
  def fetch_integrations
785
785
  Async do
@@ -793,7 +793,7 @@ module Discorb
793
793
  # @macro async
794
794
  # @macro http
795
795
  #
796
- # @return [Discorb::Guild::Widget] The widget.
796
+ # @return [Async::Task<Discorb::Guild::Widget>] The widget.
797
797
  #
798
798
  def fetch_widget
799
799
  Async do
@@ -807,7 +807,7 @@ module Discorb
807
807
  # @macro async
808
808
  # @macro http
809
809
  #
810
- # @return [Discorb::Guild::VanityInvite] The vanity URL.
810
+ # @return [Async::Task<Discorb::Guild::VanityInvite>] The vanity URL.
811
811
  #
812
812
  def fetch_vanity_invite
813
813
  Async do
@@ -821,7 +821,7 @@ module Discorb
821
821
  # @macro async
822
822
  # @macro http
823
823
  #
824
- # @return [Discorb::Guild::WelcomeScreen] The welcome screen.
824
+ # @return [Async::Task<Discorb::Guild::WelcomeScreen>] The welcome screen.
825
825
  #
826
826
  def fetch_welcome_screen
827
827
  Async do
@@ -835,7 +835,7 @@ module Discorb
835
835
  # @macro async
836
836
  # @macro http
837
837
  #
838
- # @return [Array<Discorb::Sticker::GuildSticker>] The stickers.
838
+ # @return [Async::Task<Array<Discorb::Sticker::GuildSticker>>] The stickers.
839
839
  #
840
840
  def fetch_stickers
841
841
  Async do
@@ -851,8 +851,8 @@ module Discorb
851
851
  #
852
852
  # @param [#to_s] id The ID of the sticker.
853
853
  #
854
- # @return [Discorb::Sticker::GuildSticker] The sticker.
855
- # @return [nil] If the sticker does not exist.
854
+ # @return [Async::Task<Discorb::Sticker::GuildSticker>] The sticker.
855
+ # @return [Async::Task<nil>] If the sticker does not exist.
856
856
  #
857
857
  def fetch_sticker(id)
858
858
  Async do
@@ -869,7 +869,7 @@ module Discorb
869
869
  # @macro async
870
870
  # @macro http
871
871
  #
872
- # @return [Discorb::GuildTemplate] The templates.
872
+ # @return [Async::Task<Discorb::GuildTemplate>] The templates.
873
873
  #
874
874
  def fetch_templates
875
875
  Async do
@@ -882,7 +882,7 @@ module Discorb
882
882
  # Almost the same as {#fetch_templates}, but returns a single template.
883
883
  #
884
884
  # @return [Discorb::GuildTemplate] The template.
885
- # @return [nil] If the template does not exist.
885
+ # @return [Async::Task<nil>] If the template does not exist.
886
886
  #
887
887
  def fetch_template
888
888
  Async do
@@ -897,7 +897,7 @@ module Discorb
897
897
  # @param [String] description The description of the template.
898
898
  # @param [String] reason The reason for creating the template.
899
899
  #
900
- # @return [Discorb::GuildTemplate] The template.
900
+ # @return [Async::Task<Discorb::GuildTemplate>] The template.
901
901
  #
902
902
  def create_template(name, description = nil, reason: nil)
903
903
  Async do
data/lib/discorb/http.rb CHANGED
@@ -25,8 +25,8 @@ module Discorb
25
25
  # @param [String] audit_log_reason The audit log reason to send with the request.
26
26
  # @param [Hash] kwargs The keyword arguments.
27
27
  #
28
- # @return [Array[Net::HTTPResponse, Hash]] The response and as JSON.
29
- # @return [Array[Net::HTTPResponse, nil]] The response was 204.
28
+ # @return [Array(Net::HTTPResponse, Hash)] The response and as JSON.
29
+ # @return [Async::Task<Array(Net::HTTPResponse, nil)>] The response was 204.
30
30
  #
31
31
  # @raise [Discorb::HTTPError] The request was failed.
32
32
  #
@@ -56,8 +56,8 @@ module Discorb
56
56
  # @param [String] audit_log_reason The audit log reason to send with the request.
57
57
  # @param [Hash] kwargs The keyword arguments.
58
58
  #
59
- # @return [Array[Net::HTTPResponse, Hash]] The response and as JSON.
60
- # @return [Array[Net::HTTPResponse, nil]] The response was 204.
59
+ # @return [Array(Net::HTTPResponse, Hash)] The response and as JSON.
60
+ # @return [Async::Task<Array(Net::HTTPResponse, nil)>] The response was 204.
61
61
  #
62
62
  # @raise [Discorb::HTTPError] The request was failed.
63
63
  #
@@ -86,8 +86,8 @@ module Discorb
86
86
  # @param [String] audit_log_reason The audit log reason to send with the request.
87
87
  # @param [Hash] kwargs The keyword arguments.
88
88
  #
89
- # @return [Array[Net::HTTPResponse, Hash]] The response and as JSON.
90
- # @return [Array[Net::HTTPResponse, nil]] The response was 204.
89
+ # @return [Array(Net::HTTPResponse, Hash)] The response and as JSON.
90
+ # @return [Async::Task<Array(Net::HTTPResponse, nil)>] The response was 204.
91
91
  #
92
92
  # @raise [Discorb::HTTPError] The request was failed.
93
93
  #
@@ -116,8 +116,8 @@ module Discorb
116
116
  # @param [String] audit_log_reason The audit log reason to send with the request.
117
117
  # @param [Hash] kwargs The keyword arguments.
118
118
  #
119
- # @return [Array[Net::HTTPResponse, Hash]] The response and as JSON.
120
- # @return [Array[Net::HTTPResponse, nil]] The response was 204.
119
+ # @return [Array(Net::HTTPResponse, Hash)] The response and as JSON.
120
+ # @return [Async::Task<Array(Net::HTTPResponse, nil)>] The response was 204.
121
121
  #
122
122
  # @raise [Discorb::HTTPError] The request was failed.
123
123
  #
@@ -145,8 +145,8 @@ module Discorb
145
145
  # @param [String] audit_log_reason The audit log reason to send with the request.
146
146
  # @param [Hash] kwargs The keyword arguments.
147
147
  #
148
- # @return [Array[Net::HTTPResponse, Hash]] The response and as JSON.
149
- # @return [Array[Net::HTTPResponse, nil]] The response was 204.
148
+ # @return [Array(Net::HTTPResponse, Hash)] The response and as JSON.
149
+ # @return [Async::Task<Array(Net::HTTPResponse, nil)>] The response was 204.
150
150
  #
151
151
  # @raise [Discorb::HTTPError] The request was failed.
152
152
  #
@@ -175,7 +175,7 @@ module Discorb
175
175
  # @param [Hash] payload The payload to send.
176
176
  # @param [Array<Discorb::File>] files The files to send.
177
177
  #
178
- # @return [Array[String, String]] The boundary and body.
178
+ # @return [Array(String, String)] The boundary and body.
179
179
  #
180
180
  def self.multipart(payload, files)
181
181
  boundary = "DiscorbBySevenC7CMultipartFormData#{Time.now.to_f}"
@@ -203,6 +203,8 @@ module Discorb
203
203
  case resp.code
204
204
  when "400"
205
205
  raise BadRequestError.new(resp, data)
206
+ when "401"
207
+ raise UnauthorizedError.new(resp, data)
206
208
  when "403"
207
209
  raise ForbiddenError.new(resp, data)
208
210
  when "404"
@@ -26,7 +26,6 @@ module Discorb
26
26
  #
27
27
  # @param guilds [Boolean] Whether guild related events are enabled.
28
28
  # @param members [Boolean] Whether guild members related events are enabled.
29
- # @note You must enable members intent on developers portal.
30
29
  # @param bans [Boolean] Whether guild ban related events are enabled.
31
30
  # @param emojis [Boolean] Whether guild emojis related events are enabled.
32
31
  # @param integrations [Boolean] Whether guild integration related events are enabled.
@@ -34,13 +33,14 @@ module Discorb
34
33
  # @param invites [Boolean] Whether guild invite related events are enabled.
35
34
  # @param voice_states [Boolean] Whether guild voice state related events are enabled.
36
35
  # @param presences [Boolean] Whether guild presences related events are enabled.
37
- # @note You must enable members intent on developers portal.
38
36
  # @param messages [Boolean] Whether guild messages related events are enabled.
39
37
  # @param reactions [Boolean] Whether guild reaction related events are enabled.
40
38
  # @param dm_messages [Boolean] Whether dm messages related events are enabled.
41
39
  # @param dm_reactions [Boolean] Whether dm reactions related events are enabled.
42
40
  # @param dm_typing [Boolean] Whether dm typing related events are enabled.
43
41
  #
42
+ # @note You must enable privileged intents to use `members` and/or `presences` intents.
43
+ #
44
44
  def initialize(guilds: true,
45
45
  members: false,
46
46
  bans: true,
@@ -64,6 +64,7 @@ module Discorb
64
64
  end
65
65
 
66
66
  alias fired_by target
67
+ alias from target
67
68
 
68
69
  def inspect
69
70
  "#<#{self.class} id=#{@id}>"
@@ -121,7 +122,7 @@ module Discorb
121
122
  # @param [Discorb::Embed] embed The embed to send.
122
123
  # @param [Array<Discorb::Embed>] embeds The embeds to send. (max: 10)
123
124
  # @param [Discorb::AllowedMentions] allowed_mentions The allowed mentions to send.
124
- # @param [Array<Discorb::Components>, Array<Array<Discorb::Components>>] components The components to send.
125
+ # @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components The components to send.
125
126
  # @param [Boolean] ephemeral Whether to make the response ephemeral.
126
127
  #
127
128
  def post(content = nil, tts: false, embed: nil, embeds: nil, allowed_mentions: nil, components: nil, ephemeral: false)
@@ -195,7 +196,7 @@ module Discorb
195
196
  # @param [Discorb::Embed] embed The embed to send.
196
197
  # @param [Array<Discorb::Embed>] embeds The embeds to send. (max: 10)
197
198
  # @param [Discorb::AllowedMentions] allowed_mentions The allowed mentions to send.
198
- # @param [Array<Discorb::Components>, Array<Array<Discorb::Components>>] components The components to send.
199
+ # @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components The components to send.
199
200
  # @param [Boolean] ephemeral Whether to make the response ephemeral.
200
201
  #
201
202
  def edit(content, tts: false, embed: nil, embeds: nil, allowed_mentions: nil, components: nil, ephemeral: false)
data/lib/discorb/log.rb CHANGED
@@ -22,34 +22,34 @@ module Discorb
22
22
  raise ArgumentError, "Invalid log level: #{level}" unless @level
23
23
  end
24
24
 
25
- def debug(message)
25
+ def debug(message, fallback: nil)
26
26
  return unless @level <= 0
27
27
 
28
- write_output("DEBUG", "\e[90m", message)
28
+ write_output("DEBUG", "\e[90m", message, fallback)
29
29
  end
30
30
 
31
- def info(message)
31
+ def info(message, fallback: nil)
32
32
  return unless @level <= 1
33
33
 
34
- write_output("INFO", "\e[94m", message)
34
+ write_output("INFO", "\e[94m", message, fallback)
35
35
  end
36
36
 
37
- def warn(message)
37
+ def warn(message, fallback: nil)
38
38
  return unless @level <= 2
39
39
 
40
- write_output("WARN", "\e[93m", message)
40
+ write_output("WARN", "\e[93m", message, fallback)
41
41
  end
42
42
 
43
- def error(message)
43
+ def error(message, fallback: nil)
44
44
  return unless @level <= 3
45
45
 
46
- write_output("ERROR", "\e[31m", message)
46
+ write_output("ERROR", "\e[31m", message, fallback)
47
47
  end
48
48
 
49
- def fatal(message)
49
+ def fatal(message, fallback: nil)
50
50
  return unless @level <= 4
51
51
 
52
- write_output("FATAL", "\e[91m", message)
52
+ write_output("FATAL", "\e[91m", message, fallback)
53
53
  end
54
54
 
55
55
  class << self
@@ -58,8 +58,12 @@ module Discorb
58
58
 
59
59
  private
60
60
 
61
- def write_output(name, color, message)
62
- return unless @out
61
+ def write_output(name, color, message, fallback)
62
+ unless @out
63
+ fallback.puts(message) if fallback
64
+
65
+ return
66
+ end
63
67
 
64
68
  if @colorize_log
65
69
  @out.puts("\e[2;90m[#{Time.now.iso8601}] #{color}#{name}\e[m -- #{message}")
@@ -104,7 +104,7 @@ module Discorb
104
104
  end
105
105
 
106
106
  def roles
107
- @role_ids.map { |r| guild.roles[r] }
107
+ @role_ids.map { |r| guild.roles[r] }.sort_by(&:position)
108
108
  end
109
109
 
110
110
  def permissions
@@ -211,7 +211,7 @@ module Discorb
211
211
  # @param [Integer] delete_message_days The number of days to delete messages.
212
212
  # @param [String] reason The reason for the action.
213
213
  #
214
- # @return [Discorb::Guild::Ban] The ban.
214
+ # @return [Async::Task<Discorb::Guild::Ban>] The ban.
215
215
  #
216
216
  def ban(delete_message_days: 0, reason: nil)
217
217
  Async do
@@ -234,7 +234,7 @@ module Discorb
234
234
  @custom_avatar = member_data[:avatar] && Asset.new(member_data[:avatar])
235
235
  super(user_data)
236
236
  @display_avatar = @avatar || @custom_avatar
237
- @client.guilds[@guild_id].members[@id] = self unless @guild_id.nil?
237
+ @client.guilds[@guild_id].members[@id] = self unless @guild_id.nil? || @client.guilds[@guild_id].nil?
238
238
  @_member_data.update(member_data)
239
239
  end
240
240
  end
@@ -128,7 +128,7 @@ module Discorb
128
128
  attr_reader :interaction
129
129
  # @return [Discorb::ThreadChannel] The thread channel of the message.
130
130
  attr_reader :thread
131
- # @return [Array<Array<Discorb::Components>>] The components of the message.
131
+ # @return [Array<Array<Discorb::Component>>] The components of the message.
132
132
  attr_reader :components
133
133
  # @return [Boolean] Whether the message is deleted.
134
134
  attr_reader :deleted
@@ -218,7 +218,7 @@ module Discorb
218
218
  #
219
219
  # @param [String] content The message content.
220
220
  # @param [Discorb::Embed] embed The embed to send.
221
- # @param [Array<Discord::Embed>] embeds The embeds to send.
221
+ # @param [Array<Discorb::Embed>] embeds The embeds to send.
222
222
  # @param [Discorb::AllowedMentions] allowed_mentions The allowed mentions.
223
223
  # @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components The components to send.
224
224
  # @param [Boolean] supress Whether to supress embeds.
@@ -266,7 +266,7 @@ module Discorb
266
266
  # @macro async
267
267
  # @macro http
268
268
  # @param (see #post)
269
- # @return [Discorb::Message] The message.
269
+ # @return [Async::Task<Discorb::Message>] The message.
270
270
  def reply(*args, **kwargs)
271
271
  Async do
272
272
  channel.post(*args, reference: self, **kwargs).wait
@@ -339,7 +339,7 @@ module Discorb
339
339
  # @param [Integer, nil] limit The maximum number of users to fetch. `nil` for no limit.
340
340
  # @param [Discorb::Snowflake, nil] after The ID of the user to start fetching from.
341
341
  #
342
- # @return [Array<Discorb::User>] The users.
342
+ # @return [Async::Task<Array<Discorb::User>>] The users.
343
343
  #
344
344
  def fetch_reacted_users(emoji, limit: nil, after: 0)
345
345
  Async do
@@ -393,7 +393,7 @@ module Discorb
393
393
  #
394
394
  # @param (see Discorb::Channel#start_thread)
395
395
  #
396
- # @return [<Type>] <description>
396
+ # @return [Async::Task<<Type>>] <description>
397
397
  #
398
398
  def start_thread(*args, **kwargs)
399
399
  Async do
@@ -522,11 +522,11 @@ module Discorb
522
522
  if data[:member].nil? && data[:webhook_id]
523
523
  @webhook_id = Snowflake.new(data[:webhook_id])
524
524
  @author = Webhook::Message::Author.new(data[:author])
525
- elsif data[:guild_id].nil? || data[:guild_id].empty?
525
+ elsif data[:guild_id].nil? || data[:guild_id].empty? || data[:member].nil?
526
526
  @author = @client.users[data[:author][:id]] || User.new(@client, data[:author])
527
527
  else
528
- @author = guild.members[data[:author][:id]] || Member.new(@client,
529
- @guild_id, data[:author], data[:member])
528
+ @author = guild&.members&.get(data[:author][:id]) || Member.new(@client,
529
+ @guild_id, data[:author], data[:member])
530
530
  end
531
531
  @content = data[:content]
532
532
  @created_at = Time.iso8601(data[:timestamp])
@@ -16,11 +16,11 @@ module Discorb
16
16
  # @param [Array<Discorb::Embed>] embeds The embeds to send.
17
17
  # @param [Discorb::AllowedMentions] allowed_mentions The allowed mentions.
18
18
  # @param [Discorb::Message, Discorb::Message::Reference] reference The message to reply to.
19
- # @param [Array<Discorb::Components>, Array<Array<Discorb::Components>>] components The components to send.
19
+ # @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components The components to send.
20
20
  # @param [Discorb::File] file The file to send.
21
21
  # @param [Array<Discorb::File>] files The files to send.
22
22
  #
23
- # @return [Discorb::Message] The message sent.
23
+ # @return [Async::Task<Discorb::Message>] The message sent.
24
24
  #
25
25
  def post(content = nil, tts: false, embed: nil, embeds: nil, allowed_mentions: nil,
26
26
  reference: nil, components: nil, file: nil, files: nil)
@@ -76,7 +76,7 @@ module Discorb
76
76
  # @param [#to_s] message_id The message id.
77
77
  # @param [String] content The message content.
78
78
  # @param [Discorb::Embed] embed The embed to send.
79
- # @param [Array<Discord::Embed>] embeds The embeds to send.
79
+ # @param [Array<Discorb::Embed>] embeds The embeds to send.
80
80
  # @param [Discorb::AllowedMentions] allowed_mentions The allowed mentions.
81
81
  # @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components The components to send.
82
82
  # @param [Boolean] supress Whether to supress embeds.
@@ -142,7 +142,7 @@ module Discorb
142
142
  #
143
143
  # @param [Discorb::Snowflake] id The ID of the message.
144
144
  #
145
- # @return [Discorb::Message] The message.
145
+ # @return [Async::Task<Discorb::Message>] The message.
146
146
  # @raise [Discorb::NotFoundError] If the message is not found.
147
147
  #
148
148
  def fetch_message(id)
@@ -162,7 +162,7 @@ module Discorb
162
162
  # @param [Discorb::Snowflake] after The ID of the message to fetch after.
163
163
  # @param [Discorb::Snowflake] around The ID of the message to fetch around.
164
164
  #
165
- # @return [Array<Discorb::Message>] The messages.
165
+ # @return [Async::Task<Array<Discorb::Message>>] The messages.
166
166
  #
167
167
  def fetch_messages(limit = 50, before: nil, after: nil, around: nil)
168
168
  Async do
data/lib/discorb/user.rb CHANGED
@@ -56,7 +56,7 @@ module Discorb
56
56
  #
57
57
  # @param [Boolean] strict Whether don't allow if the user is a member of the team.
58
58
  #
59
- # @return [Boolean] Whether the user is a owner of the client.
59
+ # @return [Async::Task<Boolean>] Whether the user is a owner of the client.
60
60
  #
61
61
  def bot_owner?(strict: false)
62
62
  Async do
@@ -58,7 +58,7 @@ module Discorb
58
58
  # @param [Boolean] wait Whether to wait for the message to be sent.
59
59
  #
60
60
  # @return [Discorb::Webhook::Message] The message that was sent.
61
- # @return [nil] If `wait` is false.
61
+ # @return [Async::Task<nil>] If `wait` is false.
62
62
  #
63
63
  def post(content = nil, tts: false, embed: nil, embeds: nil, allowed_mentions: nil,
64
64
  file: nil, files: nil, username: nil, avatar_url: :unset, wait: true)
data/lib/discorb.rb CHANGED
@@ -44,7 +44,7 @@ require_order = %w[common flag dictionary error rate_limit http intents emoji_ta
44
44
  %w[application audit_logs color components event] +
45
45
  %w[file guild_template image integration interaction invite log permission] +
46
46
  %w[presence reaction role sticker utils voice_state webhook] +
47
- %w[gateway_requests gateway command] +
47
+ %w[gateway_requests gateway app_command] +
48
48
  %w[asset extension client extend]
49
49
  require_order.each do |name|
50
50
  require_relative "discorb/#{name}.rb"