descord/
lib.rs

1//! Descord is a minimal and easy to use discord api wrapper.
2//!
3//! # Example
4//! ```rust
5//! use descord::prelude::*;
6
7//! #[tokio::main]
8//! async fn main() {
9//!     let mut client = Client::new(
10//!         "TOKEN",
11//!         GatewayIntent::NON_PRIVILEGED
12//!             // for message commands
13//!             | GatewayIntent::MESSAGE_CONTENT,
14//!         "!", // default prefix for message command
15//!     )
16//!     .await;
17//!     
18//!     // register commands, events and slash commands manually
19//!     client.register_commands(vec![echo()]);
20//!     client.register_events(vec![ready()]);
21//!     client.register_slash_commands(vec![avatar()]).await;
22//!
23//!
24//!     // alternatively you can do this, this is neat but
25//!     // it is very counterintuitive since it read
26//!     // the files and find functions marked with
27//!     // proc macros
28//!
29//!     // register_all!(client => ["src/main.rs", "src/file1.rs"]);
30//!
31//!
32//!     // start the bot!
33//!     client.login().await;
34//! }
35//!
36//! // An event handler
37//! #[descord::event] // Alternatively you can do `#[descord::event(ready)]`
38//! async fn ready(data: ReadyData) {
39//!     println!(
40//!         "Logged in as {}#{}",
41//!         data.user.username, data.user.discriminator
42//!     )
43//! }
44//!
45//! // A message command
46//! //
47//! // you can also do `#[descord::command(prefix = "new_prefix")]` to change
48//! // the command prefix for this command to change
49//! // the command prefix for this command
50//! #[descord::command]
51//! async fn echo(
52//!     /// information about the messgae
53//!     msg: Message,
54//!     /// some types can be parsed automatically
55//!     echo_what: String,
56//! ) {
57//!     msg.reply(echo_what).await;
58//! }
59//!
60//! // A slash command
61//! #[descord::slash(description = "Get a user's avatar")]
62//! async fn avatar(
63//!     interaction: Interaction,
64//!     #[doc = "User to fetch avatar from"] user: Option<User>,
65//! ) {
66//!     let member = interaction.member.as_ref().unwrap();
67//!     let (username, avatar_url) = match user {
68//!         Some(user) => (
69//!             &user.username,
70//!             user.get_avatar_url(ImageFormat::WebP, None).unwrap(),
71//!         ),
72//!
73//!         _ => (
74//!             &member.user.as_ref().unwrap().username,
75//!             member.get_avatar_url(ImageFormat::WebP, None).unwrap(),
76//!         ),
77//!     };
78//!
79//!     // Creating an embed
80//!     let embed = EmbedBuilder::new()
81//!         .color(Color::Orange)
82//!         .title(&format!("{username}'s avatar"))
83//!         .image(avatar_url, None, None)
84//!         .build();
85//!
86//!     interaction.reply(embed, false).await;
87//! }
88//! ```
89
90#![allow(unused)]
91
92mod client;
93mod consts;
94mod handlers;
95mod ws;
96
97pub mod models;
98
99pub mod utils;
100pub use client::Client;
101pub use consts::color;
102pub use consts::intents;
103pub use descord_macros::*;
104pub use handlers::events::Event;
105pub use ws::payload::Payload;
106pub mod internals;
107
108// TODO: change the error type
109pub type DescordResult = Result<(), Box<dyn std::error::Error + Send>>;
110
111pub(crate) mod cache;
112
113pub mod prelude {
114    pub use super::*;
115    pub use super::{
116        color::*,
117        consts::permissions,
118        consts::ButtonStyle,
119        consts::ComponentType,
120        consts::ImageFormat,
121        consts::SelectMenuType,
122        intents::GatewayIntent,
123        models::{
124            channel::*, channel::*, component_builder::*, components::*, embed::*,
125            embed_builder::*, guild::*, interaction::*, message_response::CreateMessageData,
126            message_response::Message, reaction_response::Reaction, ready_response::*, role::Role,
127            role_response::*, user::User,
128        },
129        Payload,
130    };
131}