@@ -76,12 +76,8 @@ pub use crate::CacheAndHttp;
76
76
/// A builder implementing [`Future`] building a [`Client`] to interact with Discord.
77
77
#[ cfg( feature = "gateway" ) ]
78
78
pub struct ClientBuilder < ' a > {
79
- // FIXME: Remove this allow attribute once `application_id` is no longer feature-gated
80
- // under `unstable_discord_api`.
81
- #[ allow( dead_code) ]
82
- token : Option < String > ,
83
79
data : Option < TypeMap > ,
84
- http : Option < Http > ,
80
+ http : Http ,
85
81
fut : Option < BoxFuture < ' a , Result < Client > > > ,
86
82
intents : GatewayIntents ,
87
83
#[ cfg( feature = "unstable_discord_api" ) ]
@@ -100,11 +96,10 @@ pub struct ClientBuilder<'a> {
100
96
101
97
#[ cfg( feature = "gateway" ) ]
102
98
impl < ' a > ClientBuilder < ' a > {
103
- fn _new ( ) -> Self {
99
+ fn _new ( http : Http ) -> Self {
104
100
Self {
105
- token : None ,
106
101
data : Some ( TypeMap :: new ( ) ) ,
107
- http : None ,
102
+ http,
108
103
fut : None ,
109
104
intents : GatewayIntents :: non_privileged ( ) ,
110
105
#[ cfg( feature = "unstable_discord_api" ) ]
@@ -130,7 +125,7 @@ impl<'a> ClientBuilder<'a> {
130
125
/// a framework via the [`Self::framework`] or [`Self::framework_arc`] method,
131
126
/// otherwise awaiting the builder will cause a panic.
132
127
pub fn new ( token : impl AsRef < str > ) -> Self {
133
- Self :: _new ( ) . token ( token)
128
+ Self :: _new ( Http :: new_with_token ( token. as_ref ( ) ) )
134
129
}
135
130
136
131
/// Construct a new builder with a [`Http`] instance to calls methods on
@@ -143,35 +138,30 @@ impl<'a> ClientBuilder<'a> {
143
138
///
144
139
/// [`Http`]: crate::http::Http
145
140
pub fn new_with_http ( http : Http ) -> Self {
146
- let mut c = Self :: _new ( ) ;
147
- c. http = Some ( http) ;
148
- c
141
+ Self :: _new ( http)
149
142
}
150
143
151
144
/// Sets a token for the bot. If the token is not prefixed "Bot ",
152
145
/// this method will automatically do so.
153
146
pub fn token ( mut self , token : impl AsRef < str > ) -> Self {
154
- let token = token. as_ref ( ) . trim ( ) ;
155
-
156
- let token =
157
- if token. starts_with ( "Bot " ) { token. to_string ( ) } else { format ! ( "Bot {}" , token) } ;
158
-
159
- self . token = Some ( token. clone ( ) ) ;
160
-
161
- self . http = Some ( Http :: new_with_token ( & token) ) ;
147
+ self . http = Http :: new_with_token ( token. as_ref ( ) ) ;
162
148
163
149
self
164
150
}
165
151
152
+ /// Gets the current token used for the [`Http`] client.
153
+ ///
154
+ /// [`Http`]: crate::http::Http
155
+ pub fn get_token ( & self ) -> & str {
156
+ & self . http . token
157
+ }
158
+
166
159
/// Sets the application id.
167
160
#[ cfg( feature = "unstable_discord_api" ) ]
168
161
pub fn application_id ( mut self , application_id : u64 ) -> Self {
169
162
self . application_id = Some ( ApplicationId ( application_id) ) ;
170
163
171
- self . http = Some ( Http :: new_with_token_application_id (
172
- & self . token . clone ( ) . expect ( "no token" ) ,
173
- application_id,
174
- ) ) ;
164
+ self . http = Http :: new_with_token_application_id ( self . get_token ( ) , application_id) ;
175
165
176
166
self
177
167
}
@@ -359,7 +349,7 @@ impl<'a> Future for ClientBuilder<'a> {
359
349
let event_handler = self . event_handler . take ( ) ;
360
350
let raw_event_handler = self . raw_event_handler . take ( ) ;
361
351
let intents = self . intents ;
362
- let http = Arc :: new ( self . http . take ( ) . unwrap ( ) ) ;
352
+ let http = Arc :: new ( std :: mem :: take ( & mut self . http ) ) ;
363
353
364
354
#[ cfg( feature = "unstable_discord_api" ) ]
365
355
if http. application_id == 0 {
0 commit comments