Skip to content

Commit

Permalink
fix: Check if we have the SERVER_MEMBERS intent before fetching serve…
Browse files Browse the repository at this point in the history
…r members (#53)
  • Loading branch information
kaine119 authored Sep 17, 2021
1 parent ce7fefc commit 27efa29
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/discordrb/data/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,15 @@ def member(id, request = true)
end

# @return [Array<Member>] an array of all the members on this server.
# @raise [RuntimeError] if the bot was not started with the :server_member intent
def members
return @members.values if @chunked

@bot.debug("Members for server #{@id} not chunked yet - initiating")

# If the SERVER_MEMBERS intent flag isn't set, the gateway won't respond when we ask for members.
raise 'The :server_members intent is required to get server members' if (@bot.gateway.intents & INTENTS[:server_members]).zero?

@bot.request_chunks(@id)
sleep 0.05 until @chunked
@members.values
Expand Down
3 changes: 3 additions & 0 deletions lib/discordrb/gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ class Gateway
# @return [true, false] whether or not this gateway should check for heartbeat ACKs.
attr_accessor :check_heartbeat_acks

# @return [Integer] the intent parameter sent to the gateway server.
attr_reader :intents

def initialize(bot, token, shard_key = nil, compress_mode = :stream, intents = ALL_INTENTS)
@token = token
@bot = bot
Expand Down

0 comments on commit 27efa29

Please sign in to comment.