diff --git a/.env b/.env index e8324bb..c96a59a 100644 --- a/.env +++ b/.env @@ -1 +1,3 @@ -DISCORD_TOKEN="PUT YOUR BOT TOKEN HERE" +DISCORD_INTENTS="intents / permissions integer" +DISCORD_TOKEN="Your bot token" +DISCORD_ID="Your bot id" diff --git a/README.md b/README.md index d1269c5..5a7ad7c 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,12 @@ A quick rust-based discord bot template. +## Getting started +* goto: [Discord applicatoins](https://discord.com/developers/applications) and +create an application. +* Next goto the "bot" tab on the left, and "Reset Token". KEEP THIS PRIVATE. +When are testing / deploying your bot put this token in the `.env` file. +* Next decide what permissions your bot needs. Make sure to edit `intents` in `src/main.rs` +to match this. When you are creating the invite link on discord.com you will +have to select these permissions as well. + diff --git a/src/main.rs b/src/main.rs index f32e183..755abd0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,15 +1,35 @@ -use poise::serenity_prelude as serenity; +use poise::serenity_prelude::{self as serenity, GatewayIntents}; use dotenv; mod command; pub struct Data {} // User data, which is stored and accessible in all command invocations type Context<'a> = poise::Context<'a, Data, anyhow::Error>; +const DISCORD_INTENTS: &'static str = "DISCORD_INTENTS"; +const DISCORD_TOKEN: &'static str = "DISCORD_TOKEN"; +const DISCORD_ID: &'static str = "DISCORD_ID"; + #[tokio::main] async fn main() { + // ======================================== READ ENV ======================================== dotenv::dotenv().ok(); - let token = std::env::var("DISCORD_TOKEN").expect("missing DISCORD_TOKEN"); - + let id: String = std::env::var(DISCORD_ID).expect(&format!("ERROR: Missing {DISCORD_ID}")); + let token: String = std::env::var(DISCORD_TOKEN).expect(&format!("ERROR: Missing {DISCORD_TOKEN}")); + let perm_env: String = std::env::var(DISCORD_INTENTS) + .unwrap_or_else(|msg| { + println!("DEBUG: what is: {msg}"); + println!("ERROR: Missing {DISCORD_INTENTS}"); + "0".to_string() + }); + // parse into u64, then into GatewayIntents + let perm_u64 = perm_env.parse::().unwrap_or(0u64); + let intents: GatewayIntents = GatewayIntents::from_bits(perm_u64).unwrap_or(GatewayIntents::empty()); + // Re-build into string, just incase it has changed + let perm_string = intents.bits().to_string(); + // ======================================== ENV DONE ======================================== + + // Generate sick text like this: + // http://www.patorjk.com/software/taag/#p=testall&f=Graffiti&t=hello%20world println!(r#" /$$$$$$$$ /$$ /$$ /$$$$$$$ /$$ @@ -26,12 +46,15 @@ async fn main() { Template Bot. Invite this bot with: + + https://discord.com/api/oauth2/authorize?client_id={id}&permissions={perm_string}&scope=bot "#); + // Use bitlogic "OR" to combine different intents. let intents = - serenity::GatewayIntents::GUILD_VOICE_STATES | - serenity::GatewayIntents::non_privileged(); + intents | + GatewayIntents::non_privileged(); let framework = poise::Framework::builder()