forked from Skynet/discord-bot
initial commit, bot "works"
This commit is contained in:
commit
9a158701a9
4 changed files with 1525 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
/target
|
||||
/.idea
|
1459
Cargo.lock
generated
Normal file
1459
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
10
Cargo.toml
Normal file
10
Cargo.toml
Normal file
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "skynet_discord_bot"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
serenity = { version = "0.11.6", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "cache"] }
|
||||
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
|
54
src/main.rs
Normal file
54
src/main.rs
Normal file
|
@ -0,0 +1,54 @@
|
|||
use std::env;
|
||||
|
||||
use serenity::async_trait;
|
||||
use serenity::model::channel::Message;
|
||||
use serenity::model::gateway::{GatewayIntents, Presence, Ready};
|
||||
use serenity::prelude::*;
|
||||
|
||||
struct Handler;
|
||||
// eoghanconlon73
|
||||
#[async_trait]
|
||||
impl EventHandler for Handler {
|
||||
// This event will be dispatched for guilds, but not for direct messages.
|
||||
async fn message(&self, ctx: Context, msg: Message) {
|
||||
println!("Received message: {}", msg.content);
|
||||
|
||||
|
||||
if let Some(user) = ctx.cache.user("eoghanconlon73") {
|
||||
println!("User with Id eoghanconlon73 is currently named {}", user.name);
|
||||
}
|
||||
}
|
||||
|
||||
// As the intents set in this example, this event shall never be dispatched.
|
||||
// Try it by changing your status.
|
||||
async fn presence_update(&self, _ctx: Context, _new_data: Presence) {
|
||||
println!("Presence Update");
|
||||
}
|
||||
|
||||
async fn ready(&self, _: Context, ready: Ready) {
|
||||
println!("{} is connected!", ready.user.name);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
// Configure the client with your Discord bot token in the environment.
|
||||
//let token = env::var("DISCORD_TOKEN").expect("Expected a token in the environment");
|
||||
let token = String::from("");
|
||||
|
||||
// Intents are a bitflag, bitwise operations can be used to dictate which intents to use
|
||||
let intents = GatewayIntents::GUILDS | GatewayIntents::GUILD_MESSAGES | GatewayIntents::MESSAGE_CONTENT | GatewayIntents::GUILD_MEMBERS;
|
||||
// Build our client.
|
||||
let mut client = Client::builder(token, intents)
|
||||
.event_handler(Handler)
|
||||
.await
|
||||
.expect("Error creating client");
|
||||
|
||||
// Finally, start a single shard, and start listening to events.
|
||||
//
|
||||
// Shards will automatically attempt to reconnect, and will perform
|
||||
// exponential backoff until it reconnects.
|
||||
if let Err(why) = client.start().await {
|
||||
println!("Client error: {:?}", why);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue