Class: Discordrb::Bot

Inherits:
Object
  • Object
show all
Includes:
Cache, EventContainer
Defined in:
lib/discordrb/bot.rb

Overview

Represents a Discord bot, including servers, users, etc.

Direct Known Subclasses

Commands::CommandBot

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Cache

#channel, #ensure_channel, #ensure_server, #ensure_thread_member, #ensure_user, #find_channel, #find_user, #init_cache, #invite, #member, #pm_channel, #request_chunks, #resolve_invite_code, #server, #server_preview, #user, #voice_regions

Methods included from EventContainer

#add_handler, #application_command, #application_command_permissions_update, #audit_log_entry, #autocomplete, #await, #button, #channel_create, #channel_delete, #channel_pins_update, #channel_recipient_add, #channel_recipient_remove, #channel_select, #channel_update, class_from_string, #clear!, #disconnected, event_class, handler_class, #heartbeat, #include_events, #integration_create, #integration_delete, #integration_update, #interaction_create, #invite_create, #invite_delete, #member_join, #member_leave, #member_update, #mention, #mentionable_select, #message, #message_delete, #message_edit, #message_update, #modal_submit, #playing, #pm, #presence, #raw, #reaction_add, #reaction_remove, #reaction_remove_all, #reaction_remove_emoji, #ready, #remove_application_command_handler, #remove_handler, #role_select, #scheduled_event_create, #scheduled_event_delete, #scheduled_event_update, #scheduled_event_user_add, #scheduled_event_user_remove, #server_create, #server_delete, #server_emoji, #server_emoji_create, #server_emoji_delete, #server_emoji_update, #server_role_create, #server_role_delete, #server_role_update, #server_update, #string_select, #typing, #unknown, #user_ban, #user_select, #user_unban, #voice_server_update, #voice_state_update, #webhook_update

Methods included from Events

#added_members, matches_all

Constructor Details

#initialize(log_mode: :normal, token: nil, client_id: nil, type: nil, name: '', fancy_log: false, suppress_ready: false, parse_self: false, shard_id: nil, num_shards: nil, redact_token: true, ignore_bots: false, compress_mode: :large, intents: :all) ⇒ Bot

Makes a new bot with the given authentication data. It will be ready to be added event handlers to and can eventually be run with #run.

As support for logging in using username and password has been removed in version 3.0.0, only a token login is possible. Be sure to specify the type parameter as :user if you're logging in as a user.

Simply creating a bot won't be enough to start sending messages etc. with, only a limited set of methods can be used after logging in. If you want to do something when the bot has connected successfully, either do it in the EventContainer#ready event, or use the #run method with the :async parameter and do the processing after that.

Parameters:

  • log_mode (Symbol) (defaults to: :normal)

    The mode this bot should use for logging. See Logger#mode= for a list of modes.

  • token (String) (defaults to: nil)

    The token that should be used to log in. If your bot is a bot account, you have to specify this. If you're logging in as a user, make sure to also set the account type to :user so discordrb doesn't think you're trying to log in as a bot.

  • client_id (Integer) (defaults to: nil)

    If you're logging in as a bot, the bot's client ID. This is optional, and may be fetched from the API by calling #bot_application (see Application).

  • type (Symbol) (defaults to: nil)

    This parameter lets you manually overwrite the account type. This needs to be set when logging in as a user, otherwise discordrb will treat you as a bot account. Valid values are :user and :bot.

  • name (String) (defaults to: '')

    Your bot's name. This will be sent to Discord with any API requests, who will use this to trace the source of excessive API requests; it's recommended to set this to something if you make bots that many people will host on their servers separately.

  • fancy_log (true, false) (defaults to: false)

    Whether the output log should be made extra fancy using ANSI escape codes. (Your terminal may not support this.)

  • suppress_ready (true, false) (defaults to: false)

    Whether the READY packet should be exempt from being printed to console. Useful for very large bots running in debug or verbose log_mode.

  • parse_self (true, false) (defaults to: false)

    Whether the bot should react on its own messages. It's best to turn this off unless you really need this so you don't inadvertently create infinite loops.

  • shard_id (Integer) (defaults to: nil)

    The number of the shard this bot should handle. See https://github.com/discord/discord-api-docs/issues/17 for how to do sharding.

  • num_shards (Integer) (defaults to: nil)

    The total number of shards that should be running. See https://github.com/discord/discord-api-docs/issues/17 for how to do sharding.

  • redact_token (true, false) (defaults to: true)

    Whether the bot should redact the token in logs. Default is true.

  • ignore_bots (true, false) (defaults to: false)

    Whether the bot should ignore bot accounts or not. Default is false.

  • compress_mode (:none, :large, :stream) (defaults to: :large)

    Sets which compression mode should be used when connecting to Discord's gateway. :none will request that no payloads are received compressed (not recommended for production bots). :large will request that large payloads are received compressed. :stream will request that all data be received in a continuous compressed stream.

  • intents (:all, :unprivileged, Array<Symbol>, :none, Integer) (defaults to: :all)

    Gateway intents that this bot requires. :all will request all intents. :unprivileged will request only intents that are not defined as "Privileged". :none will request no intents. An array of symbols will request only those intents specified. An integer value will request exactly all the intents specified in the bitwise value.

See Also:



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/discordrb/bot.rb', line 116

def initialize(
  log_mode: :normal,
  token: nil, client_id: nil,
  type: nil, name: '', fancy_log: false, suppress_ready: false, parse_self: false,
  shard_id: nil, num_shards: nil, redact_token: true, ignore_bots: false,
  compress_mode: :large, intents: :all
)
  LOGGER.mode = log_mode
  LOGGER.token = token if redact_token

  @should_parse_self = parse_self

  @client_id = client_id

  @type = type || :bot
  @name = name

  @shard_key = num_shards ? [shard_id, num_shards] : nil

  LOGGER.fancy = fancy_log
  @prevent_ready = suppress_ready

  @compress_mode = compress_mode

  raise 'Token string is empty or nil' if token.nil? || token.empty?

  @intents = case intents
             when :all
               ALL_INTENTS
             when :unprivileged
               UNPRIVILEGED_INTENTS
             when :none
               NO_INTENTS
             else
               calculate_intents(intents)
             end

  @token = process_token(@type, token)
  @gateway = Gateway.new(self, @token, @shard_key, @compress_mode, @intents)

  init_cache

  @voices = {}
  @should_connect_to_voice = {}

  @ignored_ids = Set.new
  @ignore_bots = ignore_bots

  @event_threads = []
  @current_thread = 0

  @status = :online

  @application_commands = {}
  @request_members_rl = {}
end

Instance Attribute Details

#awaitsHash<Symbol => Await> (readonly)

Returns the list of registered Awaits.

Returns:

  • (Hash<Symbol => Await>)

    the list of registered Awaits.



65
66
67
# File 'lib/discordrb/bot.rb', line 65

def awaits
  @awaits
end

#event_threadsArray<Thread> (readonly)

The list of currently running threads used to parse and call events. The threads will have a local variable :discordrb_name in the format of et-1234, where "et" stands for "event thread" and the number is a continually incrementing number representing how many events were executed before.

Returns:

  • (Array<Thread>)

    The threads.



51
52
53
# File 'lib/discordrb/bot.rb', line 51

def event_threads
  @event_threads
end

#gatewayGateway (readonly)

The gateway connection is an internal detail that is useless to most people. It is however essential while debugging or developing discordrb itself, or while writing very custom bots.

Returns:



70
71
72
# File 'lib/discordrb/bot.rb', line 70

def gateway
  @gateway
end

#nameString

The bot's name which discordrb sends to Discord when making any request, so Discord can identify bots with the same codebase. Not required but I recommend setting it anyway.

Returns:

  • (String)

    The bot's name.



59
60
61
# File 'lib/discordrb/bot.rb', line 59

def name
  @name
end

#shard_keyArray(Integer, Integer) (readonly)

Returns the current shard key.

Returns:



62
63
64
# File 'lib/discordrb/bot.rb', line 62

def shard_key
  @shard_key
end

#should_parse_selftrue, false

Returns whether or not the bot should parse its own messages. Off by default.

Returns:

  • (true, false)

    whether or not the bot should parse its own messages. Off by default.



54
55
56
# File 'lib/discordrb/bot.rb', line 54

def should_parse_self
  @should_parse_self
end

#voicesHash<Integer => VoiceBot> (readonly)

Returns the voice connections this bot currently has, by the server ID to which they are connected.

Returns:

  • (Hash<Integer => VoiceBot>)

    the voice connections this bot currently has, by the server ID to which they are connected.



343
344
345
# File 'lib/discordrb/bot.rb', line 343

def voices
  @voices
end

Instance Method Details

#accept_invite(invite) ⇒ Object

Makes the bot join an invite to a server.

Parameters:



317
318
319
320
# File 'lib/discordrb/bot.rb', line 317

def accept_invite(invite)
  resolved = invite(invite).code
  API::Invite.accept(token, resolved)
end

#add_await(key, type, attributes = {}) {|event| ... } ⇒ Await

Deprecated.

Will be changed to blocking behavior in v4.0. Use #add_await! instead.

Add an await the bot should listen to. For information on awaits, see Await.

Parameters:

  • key (Symbol)

    The key that uniquely identifies the await for Events::AwaitEvents to listen to (see EventContainer#await).

  • type (Class)

    The event class that should be listened for.

  • attributes (Hash) (defaults to: {})

    The attributes the event should check for. The block will only be executed if all attributes match.

Yields:

  • Is executed when the await is triggered.

Yield Parameters:

  • event (Event)

    The event object that was triggered.

Returns:

  • (Await)

    The await that was created.



699
700
701
702
703
704
705
# File 'lib/discordrb/bot.rb', line 699

def add_await(key, type, attributes = {}, &block)
  raise "You can't await an AwaitEvent!" if type == Discordrb::Events::AwaitEvent

  await = Await.new(self, key, type, attributes, block)
  @awaits ||= {}
  @awaits[key] = await
end

#add_await!(type, attributes = {}) {|event| ... } ⇒ Event?

Awaits an event, blocking the current thread until a response is received.

Parameters:

  • type (Class)

    The event class that should be listened for.

  • attributes (Hash) (defaults to: {})

    a customizable set of options

Options Hash (attributes):

  • :timeout (Numeric)

    the amount of time (in seconds) to wait for a response before returning nil. Waits forever if omitted.

Yields:

  • Executed when a matching event is received.

Yield Parameters:

  • event (Event)

    The event object that was triggered.

Yield Returns:

  • (true, false)

    Whether the event matches extra await criteria described by the block

Returns:

  • (Event, nil)

    The event object that was triggered, or nil if a timeout was set and no event was raised in time.

Raises:

  • (ArgumentError)

    if timeout is given and is not a positive numeric value



715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
# File 'lib/discordrb/bot.rb', line 715

def add_await!(type, attributes = {})
  raise "You can't await an AwaitEvent!" if type == Discordrb::Events::AwaitEvent

  timeout = attributes[:timeout]
  raise ArgumentError, 'Timeout must be a number > 0' if timeout.is_a?(Numeric) && !timeout.positive?

  mutex = Mutex.new
  cv = ConditionVariable.new
  response = nil
  block = lambda do |event|
    mutex.synchronize do
      response = event
      if block_given?
        result = yield(event)
        cv.signal if result.is_a?(TrueClass)
      else
        cv.signal
      end
    end
  end

  handler = register_event(type, attributes, block)

  if timeout
    Thread.new do
      sleep timeout
      mutex.synchronize { cv.signal }
    end
  end

  mutex.synchronize { cv.wait(mutex) }

  remove_handler(handler)
  raise 'ConditionVariable was signaled without returning an event!' if response.nil? && timeout.nil?

  response
end

#add_thread_member(channel, member) ⇒ Object

Add a member to a thread

Parameters:



662
663
664
665
# File 'lib/discordrb/bot.rb', line 662

def add_thread_member(channel, member)
  API::Channel.add_thread_member(@token, channel.resolve_id, member.resolve_id)
  nil
end

#application_command_permissions(server_id:) ⇒ Array<ApplicationCommand::Permission>

Get the permissions for all of the application commands in a specific server.

Parameters:

  • server_id (Integer, String, nil)

    The ID of the server to fetch application command permissions for.

Returns:



928
929
930
931
# File 'lib/discordrb/bot.rb', line 928

def application_command_permissions(server_id:)
  response = API::Application.get_guild_application_command_permissions(@token, profile.id, server_id.resolve_id)
  JSON.parse(response).flat_map { |data| data['permissions'].map { |inner| ApplicationCommand::Permission.new(inner, data, self) } }
end

#application_emoji(emoji_id) ⇒ Emoji

Fetches a single application emoji from its ID.

Parameters:

Returns:

  • (Emoji)

    The application emoji.



943
944
945
946
# File 'lib/discordrb/bot.rb', line 943

def application_emoji(emoji_id)
  response = API::Application.get_application_emoji(@token, profile.id, emoji_id.resolve_id)
  Emoji.new(JSON.parse(response), self)
end

#application_emojisArray<Emoji>

Fetches all the application emojis that the bot can use.

Returns:

  • (Array<Emoji>)

    Returns an array of emoji objects.



935
936
937
938
# File 'lib/discordrb/bot.rb', line 935

def application_emojis
  response = API::Application.list_application_emojis(@token, profile.id)
  JSON.parse(response)['items'].map { |emoji| Emoji.new(emoji, self) }
end

#bot_applicationApplication Also known as: bot_app, application

The bot's OAuth application.

Returns:



245
246
247
248
# File 'lib/discordrb/bot.rb', line 245

def bot_application
  response = API.oauth_application(token)
  Application.new(JSON.parse(response), self)
end

#competing=(name) ⇒ String

Sets the currently competing status to the specified name.

Parameters:

  • name (String)

    The name of the game to be competing in.

Returns:

  • (String)

    The game that is being competed in now.



612
613
614
615
# File 'lib/discordrb/bot.rb', line 612

def competing=(name)
  gateway_check
  update_status(@status, name, nil, nil, nil, 5)
end

#connected?true, false

Returns whether or not the bot is currently connected to Discord.

Returns:

  • (true, false)

    whether or not the bot is currently connected to Discord.



311
312
313
# File 'lib/discordrb/bot.rb', line 311

def connected?
  @gateway.open?
end

#create_application_emoji(name:, image:) ⇒ Emoji

Creates a new custom emoji that can be used by this application.

Parameters:

  • name (String)

    The name of emoji to create.

  • image (String, #read)

    Base64 string with the image data, or an object that responds to #read.

Returns:

  • (Emoji)

    The emoji that has been created.



952
953
954
955
956
# File 'lib/discordrb/bot.rb', line 952

def create_application_emoji(name:, image:)
  image = image.respond_to?(:read) ? Discordrb.encode64(image) : image
  response = API::Application.create_application_emoji(@token, profile.id, name, image)
  Emoji.new(JSON.parse(response), self)
end

#create_oauth_application(name, redirect_uris) ⇒ Array(String, String)

Creates a new application to do OAuth authorization with. This allows you to use OAuth to authorize users using Discord. For information how to use this, see the docs: https://discord.com/developers/docs/topics/oauth2

Parameters:

  • name (String)

    What your application should be called.

  • redirect_uris (Array<String>)

    URIs that Discord should redirect your users to after authorizing.

Returns:

  • (Array(String, String))

    your applications' client ID and client secret to be used in OAuth authorization.



492
493
494
495
# File 'lib/discordrb/bot.rb', line 492

def create_oauth_application(name, redirect_uris)
  response = JSON.parse(API.create_oauth_application(@token, name, redirect_uris))
  [response['id'], response['secret']]
end

#debug(message) ⇒ Object

See Also:

  • Logger#debug


775
776
777
# File 'lib/discordrb/bot.rb', line 775

def debug(message)
  LOGGER.debug(message)
end

#debug=(new_debug) ⇒ Object

Sets debug mode. If debug mode is on, many things will be outputted to STDOUT.



676
677
678
# File 'lib/discordrb/bot.rb', line 676

def debug=(new_debug)
  LOGGER.debug = new_debug
end

#delete_application_command(command_id, server_id: nil) ⇒ Object

Remove an application command from the commands registered with discord.

Parameters:

  • command_id (String, Integer)

    The ID of the command to remove.

  • server_id (String, Integer) (defaults to: nil)

    The ID of the server to delete this command from, global if nil.



902
903
904
905
906
907
908
# File 'lib/discordrb/bot.rb', line 902

def delete_application_command(command_id, server_id: nil)
  if server_id
    API::Application.delete_guild_command(@token, profile.id, server_id, command_id)
  else
    API::Application.delete_global_command(@token, profile.id, command_id)
  end
end

#delete_application_emoji(emoji_id) ⇒ Object

Deletes an existing application emoji.

Parameters:



969
970
971
# File 'lib/discordrb/bot.rb', line 969

def delete_application_emoji(emoji_id)
  API::Application.delete_application_emoji(@token, profile.id, emoji_id.resolve_id)
end

#delete_invite(code) ⇒ Object

Revokes an invite to a server. Will fail unless you have the Manage Server permission. It is recommended that you use Invite#delete instead.

Parameters:



407
408
409
410
# File 'lib/discordrb/bot.rb', line 407

def delete_invite(code)
  invite = resolve_invite_code(code)
  API::Invite.delete(token, invite)
end

#dispatch(type, data) ⇒ Object

Dispatches an event to this bot. Called by the gateway connection handler used internally.



785
786
787
# File 'lib/discordrb/bot.rb', line 785

def dispatch(type, data)
  handle_dispatch(type, data)
end

#dndObject

Sets the bot's status to DnD (red icon).



634
635
636
637
# File 'lib/discordrb/bot.rb', line 634

def dnd
  gateway_check
  update_status(:dnd, @activity, nil)
end

#edit_application_command(command_id, server_id: nil, name: nil, description: nil, default_permission: nil, type: :chat_input, default_member_permissions: nil, contexts: nil, nsfw: nil, integration_types: nil) {|, | ... } ⇒ Object

Yield Parameters:

  • (OptionBuilder)
  • (PermissionBuilder)


871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
# File 'lib/discordrb/bot.rb', line 871

def edit_application_command(command_id, server_id: nil, name: nil, description: nil, default_permission: nil, type: :chat_input, default_member_permissions: nil, contexts: nil, nsfw: nil, integration_types: nil)
  type = ApplicationCommand::TYPES[type] || type

  contexts = contexts&.map { |context| Interaction::CONTEXTS[context] || context }
  integration_types = integration_types&.map { |type| Interaction::INTEGRATION_TYPES[type] || type }
  default_member_permissions = Permissions.bits(default_member_permissions) if default_member_permissions.is_a?(Array)

  builder = Interactions::OptionBuilder.new
  permission_builder = Interactions::PermissionBuilder.new

  yield(builder, permission_builder) if block_given?

  resp = if server_id
           API::Application.edit_guild_command(@token, profile.id, server_id, command_id, name, description, builder.to_a, default_permission, type, default_member_permissions&.to_s, contexts, nsfw)
         else
           API::Application.edit_global_command(@token, profile.id, command_id, name, description, builder.to_a, default_permission, type, default_member_permissions&.to_s, contexts, nsfw, integration_types)
         end
  cmd = ApplicationCommand.new(JSON.parse(resp), self, server_id)

  if permission_builder.to_a.any?
    raise ArgumentError, 'Permissions can only be set for guild commands' unless server_id

    edit_application_command_permissions(cmd.id, server_id, permission_builder.to_a)
  end

  cmd
end

#edit_application_command_permissions(command_id, server_id, permissions = [], bearer_token = nil) {|builder| ... } ⇒ Object

Parameters:

  • command_id (Integer, String)
  • server_id (Integer, String)
  • permissions (Array<Hash>) (defaults to: [])

    An array of objects formatted as { id: ENTITY_ID, type: 1 or 2, permission: true or false }

  • bearer_token (String) (defaults to: nil)

    A valid bearer token that has permission to manage the server and its roles.

Yields:

  • (builder)

Raises:

  • (ArgumentError)


914
915
916
917
918
919
920
921
922
923
# File 'lib/discordrb/bot.rb', line 914

def edit_application_command_permissions(command_id, server_id, permissions = [], bearer_token = nil)
  builder = Interactions::PermissionBuilder.new
  yield builder if block_given?

  raise ArgumentError, 'This method requires a valid bearer token to be provided' unless bearer_token

  permissions += builder.to_a
  bearer_token = "Bearer #{bearer_token.delete_prefix('Bearer ')}"
  API::Application.edit_guild_command_permissions(bearer_token, profile.id, server_id, command_id, permissions)
end

#edit_application_emoji(emoji_id, name:) ⇒ Emoji

Edits an existing application emoji.

Parameters:

  • emoji_id (Integer, String, Emoji)

    ID of the application emoji to edit.

  • name (String)

    The new name of the emoji.

Returns:

  • (Emoji)

    Returns the updated emoji object on success.



962
963
964
965
# File 'lib/discordrb/bot.rb', line 962

def edit_application_emoji(emoji_id, name:)
  response = API::Application.edit_application_emoji(@token, profile.id, emoji_id.resolve_id, name)
  Emoji.new(JSON.parse(response), self)
end

#emoji(id) ⇒ Emoji? #emojiArray<Emoji> Also known as: emojis, all_emoji

Overloads:

  • #emoji(id) ⇒ Emoji?

    Return an emoji by its ID

    Parameters:

    Returns:

    • (Emoji, nil)

      the emoji object. nil if the emoji was not found.

  • #emojiArray<Emoji>

    The list of emoji the bot can use.

    Returns:

    • (Array<Emoji>)

      the emoji available.



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/discordrb/bot.rb', line 204

def emoji(id = nil)
  if (id = id&.resolve_id)
    @servers.each_value do |server|
      emoji = server.emojis[id]
      return emoji if emoji
    end
  else
    hash = {}
    @servers.each_value do |server|
      hash.merge!(server.emojis)
    end

    hash
  end
end

#find_emoji(name) ⇒ GlobalEmoji?

Finds an emoji by its name.

Parameters:

  • name (String)

    The emoji name that should be resolved.

Returns:

  • (GlobalEmoji, nil)

    the emoji identified by the name, or nil if it couldn't be found.



226
227
228
229
# File 'lib/discordrb/bot.rb', line 226

def find_emoji(name)
  LOGGER.out("Resolving emoji #{name}")
  emoji.find { |element| element.name == name }
end

#game=(name) ⇒ String Also known as: playing=

Sets the currently playing game to the specified game.

Parameters:

  • name (String)

    The name of the game to be played.

Returns:

  • (String)

    The game that is being played now.



576
577
578
579
# File 'lib/discordrb/bot.rb', line 576

def game=(name)
  gateway_check
  update_status(@status, name, nil)
end

#get_application_command(command_id, server_id: nil) ⇒ Object

Get an application command by ID.

Parameters:

  • command_id (String, Integer)
  • server_id (String, Integer, nil) (defaults to: nil)

    The ID of the server to get the command from. Global if nil.



819
820
821
822
823
824
825
826
# File 'lib/discordrb/bot.rb', line 819

def get_application_command(command_id, server_id: nil)
  resp = if server_id
           API::Application.get_guild_command(@token, profile.id, server_id, command_id)
         else
           API::Application.get_global_command(@token, profile.id, command_id)
         end
  ApplicationCommand.new(JSON.parse(resp), self, server_id)
end

#get_application_commands(server_id: nil) ⇒ Array<ApplicationCommand>

Get all application commands.

Parameters:

  • server_id (String, Integer, nil) (defaults to: nil)

    The ID of the server to get the commands from. Global if nil.

Returns:



804
805
806
807
808
809
810
811
812
813
814
# File 'lib/discordrb/bot.rb', line 804

def get_application_commands(server_id: nil)
  resp = if server_id
           API::Application.get_guild_commands(@token, profile.id, server_id)
         else
           API::Application.get_global_commands(@token, profile.id)
         end

  JSON.parse(resp).map do |command_data|
    ApplicationCommand.new(command_data, self, server_id)
  end
end

#idleObject Also known as: away

Sets status to idle.



626
627
628
629
# File 'lib/discordrb/bot.rb', line 626

def idle
  gateway_check
  update_status(:idle, @activity, nil)
end

#ignore_user(user) ⇒ Object

Note:

Ignoring a user only prevents any message events (including mentions, commands etc.) from them! Typing and presence and any other events will still be received.

Add a user to the list of ignored users. Those users will be ignored in message events at event processing level.

Parameters:



757
758
759
# File 'lib/discordrb/bot.rb', line 757

def ignore_user(user)
  @ignored_ids << user.resolve_id
end

#ignored?(user) ⇒ true, false

Checks whether a user is being ignored.

Parameters:

Returns:

  • (true, false)

    whether or not the user is ignored.



770
771
772
# File 'lib/discordrb/bot.rb', line 770

def ignored?(user)
  @ignored_ids.include?(user.resolve_id)
end

#invisibleObject

Sets the bot's status to invisible (appears offline).



640
641
642
643
# File 'lib/discordrb/bot.rb', line 640

def invisible
  gateway_check
  update_status(:invisible, @activity, nil)
end

#invite_url(server: nil, permission_bits: nil, redirect_uri: nil, scopes: ['bot']) ⇒ String

Creates an OAuth invite URL that can be used to invite this bot to a particular server.

Parameters:

  • server (Server, nil) (defaults to: nil)

    The server the bot should be invited to, or nil if a general invite should be created.

  • permission_bits (String, Integer) (defaults to: nil)

    Permission bits that should be appended to invite url.

  • redirect_uri (String) (defaults to: nil)

    Redirect URI that should be appended to invite url.

  • scopes (Array<String>) (defaults to: ['bot'])

    Scopes that should be appended to invite url.

Returns:

  • (String)

    the OAuth invite URL.



328
329
330
331
332
333
334
335
336
337
338
339
340
# File 'lib/discordrb/bot.rb', line 328

def invite_url(server: nil, permission_bits: nil, redirect_uri: nil, scopes: ['bot'])
  @client_id ||= bot_application.id

  query = URI.encode_www_form({
    client_id: @client_id,
    guild_id: server&.id,
    permissions: permission_bits,
    redirect_uri: redirect_uri,
    scope: scopes.join(' ')
  }.compact)

  "https://discord.com/oauth2/authorize?#{query}"
end

#joinObject Also known as: sync

Joins the bot's connection thread with the current thread. This blocks execution until the websocket stops, which should only happen manually triggered. or due to an error. This is necessary to have a continuously running bot.



298
299
300
# File 'lib/discordrb/bot.rb', line 298

def join
  @gateway.sync
end

#join_thread(channel) ⇒ Object

Join a thread

Parameters:



647
648
649
650
# File 'lib/discordrb/bot.rb', line 647

def join_thread(channel)
  API::Channel.join_thread(@token, channel.resolve_id)
  nil
end

#leave_thread(channel) ⇒ Object

Leave a thread

Parameters:



654
655
656
657
# File 'lib/discordrb/bot.rb', line 654

def leave_thread(channel)
  API::Channel.leave_thread(@token, channel.resolve_id)
  nil
end

#listening=(name) ⇒ String

Sets the current listening status to the specified name.

Parameters:

  • name (String)

    The thing to be listened to.

Returns:

  • (String)

    The thing that is now being listened to.



586
587
588
589
# File 'lib/discordrb/bot.rb', line 586

def listening=(name)
  gateway_check
  update_status(@status, name, nil, nil, nil, 2)
end

#log_exception(e) ⇒ Object



780
781
782
# File 'lib/discordrb/bot.rb', line 780

def log_exception(e)
  LOGGER.log_exception(e)
end

#mode=(new_mode) ⇒ Object

Sets the logging mode

See Also:



682
683
684
# File 'lib/discordrb/bot.rb', line 682

def mode=(new_mode)
  LOGGER.mode = new_mode
end

#onlineObject Also known as: on

Sets status to online.



618
619
620
621
# File 'lib/discordrb/bot.rb', line 618

def online
  gateway_check
  update_status(:online, @activity, @streamurl)
end

#parse_mention(mention, server = nil) ⇒ User, ...

Gets the user, channel, role or emoji from a string.

Parameters:

  • mention (String)

    The mention, which should look like <@12314873129>, <#123456789>, <@&123456789> or <:name:126328:>.

  • server (Server, nil) (defaults to: nil)

    The server of the associated mention. (recommended for role parsing, to speed things up)

Returns:

  • (User, Channel, Role, Emoji)

    The user, channel, role or emoji identified by the mention, or nil if none exists.



545
546
547
# File 'lib/discordrb/bot.rb', line 545

def parse_mention(mention, server = nil)
  parse_mentions(mention, server).first
end

#parse_mentions(mentions, server = nil) ⇒ Array<User, Channel, Role, Emoji>

Gets the users, channels, roles and emoji from a string.

Parameters:

  • mentions (String)

    The mentions, which should look like <@12314873129>, <#123456789>, <@&123456789> or <:name:126328:>.

  • server (Server, nil) (defaults to: nil)

    The server of the associated mentions. (recommended for role parsing, to speed things up)

Returns:

  • (Array<User, Channel, Role, Emoji>)

    The array of users, channels, roles and emoji identified by the mentions, or nil if none exists.



511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
# File 'lib/discordrb/bot.rb', line 511

def parse_mentions(mentions, server = nil)
  array_to_return = []
  # While possible mentions may be in message
  while mentions.include?('<') && mentions.include?('>')
    # Removing all content before the next possible mention
    mentions = mentions.split('<', 2)[1]
    # Locate the first valid mention enclosed in `<...>`, otherwise advance to the next open `<`
    next unless mentions.split('>', 2).first.length < mentions.split('<', 2).first.length

    # Store the possible mention value to be validated with RegEx
    mention = mentions.split('>', 2).first
    if /@!?(?<id>\d+)/ =~ mention
      array_to_return << user(id) unless user(id).nil?
    elsif /#(?<id>\d+)/ =~ mention
      array_to_return << channel(id, server) unless channel(id, server).nil?
    elsif /@&(?<id>\d+)/ =~ mention
      if server
        array_to_return << server.role(id) unless server.role(id).nil?
      else
        @servers.each_value do |element|
          array_to_return << element.role(id) unless element.role(id).nil?
        end
      end
    elsif /(?<animated>^a|^${0}):(?<name>\w+):(?<id>\d+)/ =~ mention
      array_to_return << (emoji(id) || Emoji.new({ 'animated' => animated != '', 'name' => name, 'id' => id }, self, nil))
    end
  end
  array_to_return
end

#profileProfile Also known as: bot_user

The bot's user profile. This special user object can be used to edit user data like the current username (see Profile#username=).

Returns:

  • (Profile)

    The bot's profile that can be used to edit data.



234
235
236
237
238
239
# File 'lib/discordrb/bot.rb', line 234

def profile
  return @profile if @profile

  response = Discordrb::API::User.profile(@token)
  @profile = Profile.new(JSON.parse(response), self)
end

#prune_empty_groupsObject

Makes the bot leave any groups with no recipients remaining



795
796
797
798
799
# File 'lib/discordrb/bot.rb', line 795

def prune_empty_groups
  @channels.each_value do |channel|
    channel.leave_group if channel.group? && channel.recipients.empty?
  end
end

#raise_heartbeat_eventObject

Raises a heartbeat event. Called by the gateway connection handler used internally.



790
791
792
# File 'lib/discordrb/bot.rb', line 790

def raise_heartbeat_event
  raise_event(HeartbeatEvent.new(self))
end

#raw_tokenString

Returns the raw token, without any prefix.

Returns:

  • (String)

    the raw token, without any prefix

See Also:



270
271
272
# File 'lib/discordrb/bot.rb', line 270

def raw_token
  @token.split(' ').last
end

#register_application_command(name, description, server_id: nil, default_permission: nil, type: :chat_input, default_member_permissions: nil, contexts: nil, nsfw: false, integration_types: nil) {|, | ... } ⇒ Object

Examples:

bot.register_application_command(:reddit, 'Reddit Commands') do |cmd|
  cmd.subcommand_group(:subreddit, 'Subreddit Commands') do |group|
    group.subcommand(:hot, "What's trending") do |sub|
      sub.string(:subreddit, 'Subreddit to search')
    end
    group.subcommand(:new, "What's new") do |sub|
      sub.string(:since, 'How long ago', choices: ['this hour', 'today', 'this week', 'this month', 'this year', 'all time'])
      sub.string(:subreddit, 'Subreddit to search')
    end
  end
end

Yield Parameters:

  • (OptionBuilder)
  • (PermissionBuilder)


842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
# File 'lib/discordrb/bot.rb', line 842

def register_application_command(name, description, server_id: nil, default_permission: nil, type: :chat_input, default_member_permissions: nil, contexts: nil, nsfw: false, integration_types: nil)
  type = ApplicationCommand::TYPES[type] || type

  contexts = contexts&.map { |context| Interaction::CONTEXTS[context] || context }
  integration_types = integration_types&.map { |type| Interaction::INTEGRATION_TYPES[type] || type }
  default_member_permissions = Permissions.bits(default_member_permissions) if default_member_permissions.is_a?(Array)

  builder = Interactions::OptionBuilder.new
  permission_builder = Interactions::PermissionBuilder.new
  yield(builder, permission_builder) if block_given?

  resp = if server_id
           API::Application.create_guild_command(@token, profile.id, server_id, name, description, builder.to_a, default_permission, type, default_member_permissions&.to_s, contexts, nsfw)
         else
           API::Application.create_global_command(@token, profile.id, name, description, builder.to_a, default_permission, type, default_member_permissions&.to_s, contexts, nsfw, integration_types)
         end
  cmd = ApplicationCommand.new(JSON.parse(resp), self, server_id)

  if permission_builder.to_a.any?
    raise ArgumentError, 'Permissions can only be set for guild commands' unless server_id

    edit_application_command_permissions(cmd.id, server_id, permission_builder.to_a)
  end

  cmd
end

#remove_thread_member(channel, member) ⇒ Object

Remove a member from a thread

Parameters:



670
671
672
673
# File 'lib/discordrb/bot.rb', line 670

def remove_thread_member(channel, member)
  API::Channel.remove_thread_member(@token, channel.resolve_id, member.resolve_id)
  nil
end

#role_connection_metadata_recordsArray<RoleConnectionMetadata>

Get the role connection metadata records associated with this application.

Returns:



255
256
257
258
# File 'lib/discordrb/bot.rb', line 255

def 
  response = API::Application.(@bot.token, @id)
  JSON.parse(response).map { |role_connection| RoleConnectionMetadata.new(role_connection, @bot) }
end

#run(background = false) ⇒ Object

Note:

Running the bot in the background means that you can call some methods that require a gateway connection before that connection is established. In most cases an exception will be raised if you try to do this. If you need a way to safely run code after the bot is fully connected, use a EventContainer#ready event handler instead.

Runs the bot, which logs into Discord and connects the WebSocket. This prevents all further execution unless it is executed with background = true.

Parameters:

  • background (true, false) (defaults to: false)

    If it is true, then the bot will run in another thread to allow further execution. If it is false, this method will block until #stop is called. If the bot is run with true, make sure to eventually call #join so the script doesn't stop prematurely.



286
287
288
289
290
291
292
# File 'lib/discordrb/bot.rb', line 286

def run(background = false)
  @gateway.run_async
  return if background

  debug('Oh wait! Not exiting yet as run was run synchronously.')
  @gateway.sync
end

#send_file(channel, file, caption: nil, tts: false, filename: nil, spoiler: nil) ⇒ Object

Note:

This executes in a blocking way, so if you're sending long files, be wary of delays.

Sends a file to a channel. If it is an image, it will automatically be embedded.

Examples:

Send a file from disk

bot.send_file(83281822225530880, File.open('rubytaco.png', 'r'))

Parameters:

  • channel (Channel, String, Integer)

    The channel, or its ID, to send something to.

  • file (File)

    The file that should be sent.

  • caption (string) (defaults to: nil)

    The caption for the file.

  • tts (true, false) (defaults to: false)

    Whether or not this file's caption should be sent using Discord text-to-speech.

  • filename (String) (defaults to: nil)

    Overrides the filename of the uploaded file

  • spoiler (true, false) (defaults to: nil)

    Whether or not this file should appear as a spoiler.



471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
# File 'lib/discordrb/bot.rb', line 471

def send_file(channel, file, caption: nil, tts: false, filename: nil, spoiler: nil)
  if file.respond_to?(:read)
    if spoiler
      filename ||= File.basename(file.path)
      filename = "SPOILER_#{filename}" unless filename.start_with? 'SPOILER_'
    end
    # https://github.com/rest-client/rest-client/blob/v2.0.2/lib/restclient/payload.rb#L160
    file.define_singleton_method(:original_filename) { filename } if filename
    file.define_singleton_method(:path) { filename } if filename
  end

  channel = channel.resolve_id
  response = API::Channel.upload_file(token, channel, file, caption: caption, tts: tts)
  Message.new(JSON.parse(response), self)
end

#send_message(channel, content, tts = false, embeds = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0, nonce = nil, enforce_nonce = false) ⇒ Message

Sends a text message to a channel given its ID and the message's content.

Parameters:

  • channel (Channel, String, Integer)

    The channel, or its ID, to send something to.

  • content (String)

    The text that should be sent as a message. It is limited to 2000 characters (Discord imposed).

  • tts (true, false) (defaults to: false)

    Whether or not this message should be sent using Discord text-to-speech.

  • embeds (Hash, Discordrb::Webhooks::Embed, Array<Hash>, Array<Discordrb::Webhooks::Embed> nil) (defaults to: nil)

    The rich embed(s) to append to this message.

  • allowed_mentions (Hash, Discordrb::AllowedMentions, false, nil) (defaults to: nil)

    Mentions that are allowed to ping on this message. false disables all pings

  • message_reference (Message, String, Integer, Hash, nil) (defaults to: nil)

    The message, or message ID, to reply to if any.

  • components (View, Array<Hash>) (defaults to: nil)

    Interaction components to associate with this message.

  • flags (Integer) (defaults to: 0)

    Flags for this message. Currently only SUPPRESS_EMBEDS (1 << 2), SUPPRESS_NOTIFICATIONS (1 << 12), and IS_COMPONENTS_V2 (1 << 15) can be set.

  • nonce (String, nil) (defaults to: nil)

    A optional nonce in order to verify that a message was sent. Maximum of twenty-five characters.

  • enforce_nonce (true, false) (defaults to: false)

    whether the nonce should be enforced and used for message de-duplication.

Returns:

  • (Message)

    The message that was sent.



424
425
426
427
428
429
430
431
432
433
# File 'lib/discordrb/bot.rb', line 424

def send_message(channel, content, tts = false, embeds = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0, nonce = nil, enforce_nonce = false)
  channel = channel.resolve_id
  debug("Sending message to #{channel} with content '#{content}'")
  allowed_mentions = { parse: [] } if allowed_mentions == false
  message_reference = { message_id: message_reference.resolve_id } if message_reference.respond_to?(:resolve_id)
  embeds = (embeds.instance_of?(Array) ? embeds.map(&:to_hash) : [embeds&.to_hash]).compact

  response = API::Channel.create_message(token, channel, content, tts, embeds, nonce, attachments, allowed_mentions&.to_hash, message_reference, components, flags, enforce_nonce)
  Message.new(JSON.parse(response), self)
end

#send_temporary_message(channel, content, timeout, tts = false, embeds = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0, nonce = nil, enforce_nonce = false) ⇒ Object

Sends a text message to a channel given its ID and the message's content, then deletes it after the specified timeout in seconds.

Parameters:

  • channel (Channel, String, Integer)

    The channel, or its ID, to send something to.

  • content (String)

    The text that should be sent as a message. It is limited to 2000 characters (Discord imposed).

  • timeout (Float)

    The amount of time in seconds after which the message sent will be deleted.

  • tts (true, false) (defaults to: false)

    Whether or not this message should be sent using Discord text-to-speech.

  • embeds (Hash, Discordrb::Webhooks::Embed, Array<Hash>, Array<Discordrb::Webhooks::Embed> nil) (defaults to: nil)

    The rich embed(s) to append to this message.

  • attachments (Array<File>) (defaults to: nil)

    Files that can be referenced in embeds via attachment://file.png

  • allowed_mentions (Hash, Discordrb::AllowedMentions, false, nil) (defaults to: nil)

    Mentions that are allowed to ping on this message. false disables all pings

  • message_reference (Message, String, Integer, nil) (defaults to: nil)

    The message, or message ID, to reply to if any.

  • components (View, Array<Hash>) (defaults to: nil)

    Interaction components to associate with this message.

  • flags (Integer) (defaults to: 0)

    Flags for this message. Currently only SUPPRESS_EMBEDS (1 << 2), SUPPRESS_NOTIFICATIONS (1 << 12), and IS_COMPONENTS_V2 (1 << 15) can be set.

  • nonce (String, nil) (defaults to: nil)

    A optional nonce in order to verify that a message was sent. Maximum of twenty-five characters.

  • enforce_nonce (true, false) (defaults to: false)

    whether the nonce should be enforced and used for message de-duplication.



449
450
451
452
453
454
455
456
457
458
459
# File 'lib/discordrb/bot.rb', line 449

def send_temporary_message(channel, content, timeout, tts = false, embeds = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0, nonce = nil, enforce_nonce = false)
  Thread.new do
    Thread.current[:discordrb_name] = "#{@current_thread}-temp-msg"

    message = send_message(channel, content, tts, embeds, attachments, allowed_mentions, message_reference, components, flags, nonce, enforce_nonce)
    sleep(timeout)
    message.delete
  end

  nil
end

#serversHash<Integer => Server>

The list of servers the bot is currently in.

Returns:



183
184
185
186
187
# File 'lib/discordrb/bot.rb', line 183

def servers
  gateway_check
  unavailable_servers_check
  @servers
end

#stop(_no_sync = nil) ⇒ Object

Note:

This method no longer takes an argument as of 3.4.0

Stops the bot gracefully, disconnecting the websocket without immediately killing the thread. This means that Discord is immediately aware of the closed connection and makes the bot appear offline instantly.



306
307
308
# File 'lib/discordrb/bot.rb', line 306

def stop(_no_sync = nil)
  @gateway.stop
end

#stream(name, url) ⇒ String

Sets the currently online stream to the specified name and Twitch URL.

Parameters:

  • name (String)

    The name of the stream to display.

  • url (String)

    The url of the current Twitch stream.

Returns:

  • (String)

    The stream name that is being displayed now.



603
604
605
606
607
# File 'lib/discordrb/bot.rb', line 603

def stream(name, url)
  gateway_check
  update_status(@status, name, url)
  name
end

#suppress_ready_debugObject

Prevents the READY packet from being printed regardless of debug mode.



687
688
689
# File 'lib/discordrb/bot.rb', line 687

def suppress_ready_debug
  @prevent_ready = true
end

#thread_membersHash<Integer => Hash<Integer => Hash<String => Object>>]

The list of members in threads the bot can see.

Returns:



191
192
193
194
195
# File 'lib/discordrb/bot.rb', line 191

def thread_members
  gateway_check
  unavailable_servers_check
  @thread_members
end

#tokenString

The Discord API token received when logging in. Useful to explicitly call API methods.

Returns:



263
264
265
266
# File 'lib/discordrb/bot.rb', line 263

def token
  API.bot_name = @name
  @token
end

#unignore_user(user) ⇒ Object

Remove a user from the ignore list.

Parameters:



763
764
765
# File 'lib/discordrb/bot.rb', line 763

def unignore_user(user)
  @ignored_ids.delete(user.resolve_id)
end

#update_oauth_application(name, redirect_uris, description = '', icon = nil) ⇒ Object

Changes information about your OAuth application

Parameters:

  • name (String)

    What your application should be called.

  • redirect_uris (Array<String>)

    URIs that Discord should redirect your users to after authorizing.

  • description (String) (defaults to: '')

    A string that describes what your application does.

  • icon (String, nil) (defaults to: nil)

    A data URI for your icon image (for example a base 64 encoded image), or nil if no icon should be set or changed.



503
504
505
# File 'lib/discordrb/bot.rb', line 503

def update_oauth_application(name, redirect_uris, description = '', icon = nil)
  API.update_oauth_application(@token, name, redirect_uris, description, icon)
end

#update_status(status, activity, url, since = 0, afk = false, activity_type = 0) ⇒ Object

Updates presence status.

Parameters:

  • status (String)

    The status the bot should show up as. Can be online, dnd, idle, or invisible

  • activity (String, nil)

    The name of the activity to be played/watched/listened to/stream name on the stream.

  • url (String, nil)

    The Twitch URL to display as a stream. nil for no stream.

  • since (Integer) (defaults to: 0)

    When this status was set.

  • afk (true, false) (defaults to: false)

    Whether the bot is AFK.

  • activity_type (Integer) (defaults to: 0)

    The type of activity status to display. Can be 0 (Playing), 1 (Streaming), 2 (Listening), 3 (Watching), or 5 (Competing).

See Also:



558
559
560
561
562
563
564
565
566
567
568
569
570
571
# File 'lib/discordrb/bot.rb', line 558

def update_status(status, activity, url, since = 0, afk = false, activity_type = 0)
  gateway_check

  @activity = activity
  @status = status
  @streamurl = url
  type = url ? 1 : activity_type

  activity_obj = activity || url ? { 'name' => activity, 'url' => url, 'type' => type } : nil
  @gateway.send_status_update(status, since, activity_obj, afk)

  # Update the status in the cache
  profile.update_presence('status' => status.to_s, 'activities' => [activity_obj].compact)
end

#usersHash<Integer => User>

The list of users the bot shares a server with.

Returns:



175
176
177
178
179
# File 'lib/discordrb/bot.rb', line 175

def users
  gateway_check
  unavailable_servers_check
  @users
end

#voice(thing) ⇒ Voice::VoiceBot?

Gets the voice bot for a particular server or channel. You can connect to a new channel using the #voice_connect method.

Parameters:

  • thing (Channel, Server, Integer)

    the server or channel you want to get the voice bot for, or its ID.

Returns:

  • (Voice::VoiceBot, nil)

    the VoiceBot for the thing you specified, or nil if there is no connection yet



349
350
351
352
353
354
355
356
357
358
# File 'lib/discordrb/bot.rb', line 349

def voice(thing)
  id = thing.resolve_id
  return @voices[id] if @voices[id]

  channel = channel(id)
  return nil unless channel

  server_id = channel.server.id
  return @voices[server_id] if @voices[server_id]
end

#voice_connect(chan, encrypted = true) ⇒ Voice::VoiceBot

Connects to a voice channel, initializes network connections and returns the Voice::VoiceBot over which audio data can then be sent. After connecting, the bot can also be accessed using #voice. If the bot is already connected to voice, the existing connection will be terminated - you don't have to call Voice::VoiceBot#destroy before calling this method.

Parameters:

  • chan (Channel, String, Integer)

    The voice channel, or its ID, to connect to.

  • encrypted (true, false) (defaults to: true)

    Whether voice communication should be encrypted using (uses an XSalsa20 stream cipher for encryption and Poly1305 for authentication)

Returns:

  • (Voice::VoiceBot)

    the initialized bot over which audio data can then be sent.

Raises:

  • (ArgumentError)


368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
# File 'lib/discordrb/bot.rb', line 368

def voice_connect(chan, encrypted = true)
  raise ArgumentError, 'Unencrypted voice connections are no longer supported.' unless encrypted

  chan = channel(chan.resolve_id)
  server_id = chan.server.id

  if @voices[chan.id]
    debug('Voice bot exists already! Destroying it')
    @voices[chan.id].destroy
    @voices.delete(chan.id)
  end

  debug("Got voice channel: #{chan}")

  @should_connect_to_voice[server_id] = chan
  @gateway.send_voice_state_update(server_id.to_s, chan.id.to_s, false, false)

  debug('Voice channel init packet sent! Now waiting.')

  sleep(0.05) until @voices[server_id]
  debug('Voice connect succeeded!')
  @voices[server_id]
end

#voice_destroy(server, destroy_vws = true) ⇒ Object

Disconnects the client from a specific voice connection given the server ID. Usually it's more convenient to use Voice::VoiceBot#destroy rather than this.

Parameters:

  • server (Server, String, Integer)

    The server, or server ID, the voice connection is on.

  • destroy_vws (true, false) (defaults to: true)

    Whether or not the VWS should also be destroyed. If you're calling this method directly, you should leave it as true.



397
398
399
400
401
402
# File 'lib/discordrb/bot.rb', line 397

def voice_destroy(server, destroy_vws = true)
  server = server.resolve_id
  @gateway.send_voice_state_update(server.to_s, nil, false, false)
  @voices[server].destroy if @voices[server] && destroy_vws
  @voices.delete(server)
end

#watching=(name) ⇒ String

Sets the current watching status to the specified name.

Parameters:

  • name (String)

    The thing to be watched.

Returns:

  • (String)

    The thing that is now being watched.



594
595
596
597
# File 'lib/discordrb/bot.rb', line 594

def watching=(name)
  gateway_check
  update_status(@status, name, nil, nil, nil, 3)
end