Method: Discordrb::Bot#initialize
- Defined in:
- lib/discordrb/bot.rb
#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.
114 115 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 |
# File 'lib/discordrb/bot.rb', line 114 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 = {} end |