Add basic bot with ping command

This commit is contained in:
Em (Ethan) Ruszanowski 2023-01-09 18:38:08 -05:00
parent 025413b4b9
commit 165a77f510
No known key found for this signature in database
GPG key ID: C3E7A3C0B1491DFE
4 changed files with 1631 additions and 0 deletions

6
.gitignore vendored
View file

@ -8,3 +8,9 @@ Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
# Added by cargo
/target
/.idea/

1580
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

10
Cargo.toml Normal file
View file

@ -0,0 +1,10 @@
[package]
name = "echbot"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
poise = "0.5.2"
tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread"] }

35
src/main.rs Normal file
View file

@ -0,0 +1,35 @@
use poise::serenity_prelude as serenity;
struct Data {}
type Error = Box<dyn std::error::Error + Send + Sync>;
type Context<'a> = poise::Context<'a, Data, Error>;
// Basically a ping command
#[poise::command(slash_command, prefix_command)]
async fn slur(
ctx: Context<'_>,
) -> Result<(), Error> {
let response = "If you don't like my content or the way I act, don't watch me.";
ctx.say(response).await?;
Ok(())
}
#[tokio::main]
async fn main() {
let framework = poise::Framework::builder()
.options(poise::FrameworkOptions {
commands: vec![slur()],
..Default::default()
})
.token(std::env::var("DISCORD_TOKEN").expect("missing DISCORD_TOKEN"))
.intents(serenity::GatewayIntents::non_privileged())
.setup(|ctx, _ready, framework| {
Box::pin(async move {
poise::builtins::register_globally(ctx, &framework.options().commands).await?;
Ok(Data {})
})
});
framework.run().await.unwrap();
}