Skip to content

Commit

Permalink
Fix example breakage due to Token changes
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev committed Nov 22, 2024
1 parent 55c84be commit 414fdf7
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 113 deletions.
161 changes: 68 additions & 93 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/advanced_cooldowns/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async fn register_commands(ctx: Context<'_>) -> Result<(), Error> {

#[tokio::main]
async fn main() {
let token = std::env::var("DISCORD_TOKEN").expect("missing DISCORD_TOKEN");
let token = serenity::Token::from_env("DISCORD_TOKEN").unwrap();

let options = poise::FrameworkOptions {
commands: vec![register_commands(), dynamic_cooldowns()],
Expand All @@ -48,7 +48,7 @@ async fn main() {
..Default::default()
};

let client = serenity::Client::builder(&token, serenity::GatewayIntents::non_privileged())
let client = serenity::Client::builder(token, serenity::GatewayIntents::non_privileged())
.framework(poise::Framework::new(options))
.await;

Expand Down
6 changes: 2 additions & 4 deletions examples/basic_structure/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ mod commands;
use poise::serenity_prelude as serenity;
use std::{
collections::HashMap,
env::var,
sync::{Arc, Mutex},
time::Duration,
};
Expand Down Expand Up @@ -101,12 +100,11 @@ async fn main() {
..Default::default()
};

let token = var("DISCORD_TOKEN")
.expect("Missing `DISCORD_TOKEN` env var, see README for more information.");
let token = serenity::Token::from_env("DISCORD_TOKEN").unwrap();
let intents =
serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT;

let client = serenity::ClientBuilder::new(&token, intents)
let client = serenity::ClientBuilder::new(token, intents)
.framework(poise::Framework::new(options))
.data(Arc::new(Data {
votes: Mutex::new(HashMap::new()),
Expand Down
6 changes: 2 additions & 4 deletions examples/event_handler/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::env::var;
use std::sync::atomic::{AtomicU32, Ordering};
use std::sync::Arc;

Expand All @@ -18,8 +17,7 @@ pub struct Data {
async fn main() {
env_logger::init();

let token = var("DISCORD_TOKEN")
.expect("Missing `DISCORD_TOKEN` env var, see README for more information.");
let token = serenity::Token::from_env("DISCORD_TOKEN").unwrap();
let intents =
serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT;

Expand All @@ -28,7 +26,7 @@ async fn main() {
..Default::default()
};

let client = serenity::ClientBuilder::new(&token, intents)
let client = serenity::ClientBuilder::new(token, intents)
.framework(poise::Framework::new(options))
.data(Arc::new(Data {
poise_mentions: AtomicU32::new(0),
Expand Down
4 changes: 2 additions & 2 deletions examples/feature_showcase/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ async fn main() {
..Default::default()
};

let token = std::env::var("DISCORD_TOKEN").unwrap();
let token = serenity::Token::from_env("DISCORD_TOKEN").unwrap();
let intents =
serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT;

let client = serenity::ClientBuilder::new(&token, intents)
let client = serenity::ClientBuilder::new(token, intents)
.framework(poise::Framework::new(framework_options))
.await;

Expand Down
4 changes: 2 additions & 2 deletions examples/fluent_localization/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async fn main() {

translation::apply_translations(translations, &mut commands);

let token = std::env::var("TOKEN").unwrap();
let token = serenity::Token::from_env("DISCORD_TOKEN").unwrap();
let intents = serenity::GatewayIntents::non_privileged();

let framework = poise::Framework::builder()
Expand All @@ -81,7 +81,7 @@ async fn main() {
})
.build();

let client = serenity::ClientBuilder::new(&token, intents)
let client = serenity::ClientBuilder::new(token, intents)
.data(Arc::new(Data { translations }) as _)
.framework(framework)
.await;
Expand Down
4 changes: 2 additions & 2 deletions examples/invocation_data/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async fn register_commands(ctx: Context<'_>) -> Result<(), Error> {

#[tokio::main]
async fn main() {
let token = std::env::var("TOKEN").unwrap();
let token = serenity::Token::from_env("DISCORD_TOKEN").unwrap();
let intents =
serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT;

Expand Down Expand Up @@ -119,7 +119,7 @@ async fn main() {
..Default::default()
};

let client = serenity::ClientBuilder::new(&token, intents)
let client = serenity::ClientBuilder::new(token, intents)
.framework(poise::Framework::new(options))
.await;

Expand Down
4 changes: 2 additions & 2 deletions examples/manual_dispatch/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl serenity::EventHandler for Handler {

#[tokio::main]
async fn main() -> Result<(), Error> {
let token = std::env::var("DISCORD_TOKEN").expect("missing DISCORD_TOKEN");
let token = serenity::Token::from_env("DISCORD_TOKEN").unwrap();
let intents = serenity::GatewayIntents::non_privileged();
let mut handler = Handler {
options: poise::FrameworkOptions {
Expand All @@ -63,7 +63,7 @@ async fn main() -> Result<(), Error> {
poise::set_qualified_names(&mut handler.options.commands); // some setup

let handler = std::sync::Arc::new(handler);
let mut client = serenity::Client::builder(&token, intents)
let mut client = serenity::Client::builder(token, intents)
.event_handler::<Handler>(handler.clone())
.await?;

Expand Down
4 changes: 2 additions & 2 deletions examples/quickstart/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ async fn register_commands(ctx: Context<'_>) -> Result<(), Error> {

#[tokio::main]
async fn main() {
let token = std::env::var("DISCORD_TOKEN").expect("missing DISCORD_TOKEN");
let token = serenity::Token::from_env("DISCORD_TOKEN").unwrap();
let intents = serenity::GatewayIntents::non_privileged();

let options = poise::FrameworkOptions {
commands: vec![register_commands(), age()],
..Default::default()
};

let client = serenity::ClientBuilder::new(&token, intents)
let client = serenity::ClientBuilder::new(token, intents)
.framework(poise::Framework::new(options))
.await;

Expand Down

0 comments on commit 414fdf7

Please sign in to comment.