Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "discord"
version = "0.9.0"
authors = ["Tad Hardesty <tad@platymuus.com>"]
edition = "2021"

description = "Client library for the Discord API"
readme = "README.md"
Expand Down Expand Up @@ -29,6 +30,15 @@ base64-rs = "0.1.1"
flate2 = "1.0"
opus = { version = "0.2.1", optional = true }
multipart = { version = "0.17.0", default-features = false, features = ["client", "mock"] }
tokio = { version = "1.32.0", features = ["full"] }
tokio-tungstenite = { version = "0.20.1", features = ["native-tls"] }
futures-util = "0.3.29"
async-trait = "0.1.74"
url = "2.4.1"
rand = "0.8.5"

[dev-dependencies]
simplelog = "0.12.1"

[dependencies.chrono]
version = "0.4.11"
Expand All @@ -39,3 +49,6 @@ version = "0.2.5"
default-features = false
features = ["std"]
optional = true

[[example]]
name = "dj"
16 changes: 16 additions & 0 deletions examples/dj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,29 @@ use discord::model::Event;
use discord::{Discord, State};
use std::env;

use simplelog::{CombinedLogger, self};

// A simple DJ bot example.
// Use by issuing the command "!dj <youtube-link>" in PM or a visible text channel.
// The bot will join the voice channel of the person issuing the command.
// "!dj stop" will stop playing, and "!dj quit" will quit the voice channel.
// The bot will quit any voice channel it is the last user in.

pub fn main() {
let _ = CombinedLogger::init(vec![
simplelog::TermLogger::new(
simplelog::LevelFilter::Debug,
simplelog::Config::default(),
simplelog::TerminalMode::Mixed,
simplelog::ColorChoice::Auto,
),
//simplelog::WriteLogger::new(
// simplelog::LevelFilter::Trace,
// simplelog::Config::default(),
// File::create("discord_log_tungstenite.log").unwrap(),
//),
])
.unwrap();
// Log in to Discord using a bot token from the environment
let discord = Discord::from_bot_token(&env::var("DISCORD_TOKEN").expect("Expected token"))
.expect("login failed");
Expand Down
15 changes: 10 additions & 5 deletions src/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use serde_json::Value;
use chrono::offset::FixedOffset;
use chrono::DateTime;

use model::*;
use Object;
use crate::model::*;
use crate::Object;

macro_rules! builder {
($(#[$attr:meta] $name:ident($inner:ty);)*) => {
Expand Down Expand Up @@ -287,9 +287,14 @@ impl SendMessage {
/// The given `message_id` must be in the same channel that this message is
/// being sent to.
pub fn reply(self, message_id: MessageId, mention: bool) -> Self {
set!(self, "message_reference", json! {{
"message_id": message_id,
}}).allowed_mentions(|b| b.replied_user(mention))
set!(
self,
"message_reference",
json! {{
"message_id": message_id,
}}
)
.allowed_mentions(|b| b.replied_user(mention))
}

/// Change the message's flags.
Expand Down
Loading