1+ use std:: env;
2+
13use serenity:: async_trait;
24use serenity:: model:: channel:: Message ;
35use serenity:: model:: gateway:: Ready ;
@@ -9,8 +11,8 @@ struct Handler;
911impl EventHandler for Handler {
1012 // Set a handler for the `message` event. This is called whenever a new message is received.
1113 //
12- // Event handlers are dispatched through a threadpool, and so multiple events can be dispatched
13- // simultaneously.
14+ // Event handlers are dispatched through a threadpool, and so multiple events can be
15+ // dispatched simultaneously.
1416 async fn message ( & self , ctx : Context , msg : Message ) {
1517 if msg. content == "!ping" {
1618 // Sending a message can fail, due to a network error, an authentication error, or lack
@@ -35,8 +37,7 @@ impl EventHandler for Handler {
3537#[ tokio:: main]
3638async fn main ( ) {
3739 // Configure the client with your Discord bot token in the environment.
38- let token =
39- Token :: from_env ( "DISCORD_TOKEN" ) . expect ( "Expected a valid token in the environment" ) ;
40+ let token = env:: var ( "DISCORD_TOKEN" ) . expect ( "Expected a token in the environment" ) ;
4041 // Set gateway intents, which decides what events the bot will be notified about
4142 let intents = GatewayIntents :: GUILD_MESSAGES
4243 | GatewayIntents :: DIRECT_MESSAGES
@@ -45,7 +46,7 @@ async fn main() {
4546 // Create a new instance of the Client, logging in as a bot. This will automatically prepend
4647 // your bot token with "Bot ", which is a requirement by Discord for bot users.
4748 let mut client =
48- Client :: builder ( token, intents) . event_handler ( Handler ) . await . expect ( "Err creating client" ) ;
49+ Client :: builder ( & token, intents) . event_handler ( Handler ) . await . expect ( "Err creating client" ) ;
4950
5051 // Finally, start a single shard, and start listening to events.
5152 //
@@ -54,4 +55,4 @@ async fn main() {
5455 if let Err ( why) = client. start ( ) . await {
5556 println ! ( "Client error: {why:?}" ) ;
5657 }
57- }
58+ }
0 commit comments