ChannelRest

Struct ChannelRest 

Source
pub struct ChannelRest<'a> {
    pub channel_id: Option<u64>,
    pub guild_id: u64,
    pub client: &'a RestClient,
}

Fields§

§channel_id: Option<u64>§guild_id: u64§client: &'a RestClient

Implementations§

Source§

impl<'a> ChannelRest<'a>

Source

pub async fn create( &self, channel: Channel, ) -> Result<Channel, Box<dyn Error + Send + Sync>>

Examples found in repository?
examples/channel.rs (line 25)
5async fn main() {
6    pretty_env_logger::init();
7
8    let token = std::fs::read_to_string("token.txt").unwrap();
9
10    let client = RestClient::connect(token, None, None).await.unwrap();
11
12    println!("API Version: {}", client.api_version);
13
14    let guild_id: u64 = 1154763102554951811;
15
16    let channel = ChannelBuilder::default()
17        .name("test-channel")
18        .build()
19        .unwrap();
20
21    let mut channel = client
22        .guild(Some(guild_id))
23        .channel(None)
24        .unwrap()
25        .create(channel)
26        .await
27        .unwrap();
28
29    let channel_id = channel.id;
30    println!("Channel ID: {}", channel_id);
31
32    tokio::time::sleep(std::time::Duration::from_secs(1)).await;
33
34    channel.name = Some("test-channel-edited".to_string());
35
36    client
37        .guild(Some(guild_id))
38        .channel(None)
39        .unwrap()
40        .edit(channel)
41        .await
42        .unwrap();
43    let invite = client
44        .guild(Some(guild_id))
45        .channel(Some(channel_id))
46        .unwrap()
47        .create_invite(Default::default())
48        .await
49        .unwrap();
50
51    println!("Invite: discord.gg/{}", invite.code);
52
53    let invite_count = client
54        .guild(Some(guild_id))
55        .channel(Some(channel_id))
56        .unwrap()
57        .get_invites()
58        .await
59        .unwrap()
60        .len();
61
62    println!("Invite count: {}", invite_count);
63
64    tokio::time::sleep(std::time::Duration::from_secs(1)).await;
65
66    client
67        .guild(Some(guild_id))
68        .channel(Some(channel_id))
69        .unwrap()
70        .delete()
71        .await
72        .unwrap();
73}
Source

pub async fn edit( &self, channel: Channel, ) -> Result<Channel, Box<dyn Error + Send + Sync>>

Examples found in repository?
examples/channel.rs (line 40)
5async fn main() {
6    pretty_env_logger::init();
7
8    let token = std::fs::read_to_string("token.txt").unwrap();
9
10    let client = RestClient::connect(token, None, None).await.unwrap();
11
12    println!("API Version: {}", client.api_version);
13
14    let guild_id: u64 = 1154763102554951811;
15
16    let channel = ChannelBuilder::default()
17        .name("test-channel")
18        .build()
19        .unwrap();
20
21    let mut channel = client
22        .guild(Some(guild_id))
23        .channel(None)
24        .unwrap()
25        .create(channel)
26        .await
27        .unwrap();
28
29    let channel_id = channel.id;
30    println!("Channel ID: {}", channel_id);
31
32    tokio::time::sleep(std::time::Duration::from_secs(1)).await;
33
34    channel.name = Some("test-channel-edited".to_string());
35
36    client
37        .guild(Some(guild_id))
38        .channel(None)
39        .unwrap()
40        .edit(channel)
41        .await
42        .unwrap();
43    let invite = client
44        .guild(Some(guild_id))
45        .channel(Some(channel_id))
46        .unwrap()
47        .create_invite(Default::default())
48        .await
49        .unwrap();
50
51    println!("Invite: discord.gg/{}", invite.code);
52
53    let invite_count = client
54        .guild(Some(guild_id))
55        .channel(Some(channel_id))
56        .unwrap()
57        .get_invites()
58        .await
59        .unwrap()
60        .len();
61
62    println!("Invite count: {}", invite_count);
63
64    tokio::time::sleep(std::time::Duration::from_secs(1)).await;
65
66    client
67        .guild(Some(guild_id))
68        .channel(Some(channel_id))
69        .unwrap()
70        .delete()
71        .await
72        .unwrap();
73}
Source

pub async fn delete(&self) -> Result<Channel, Box<dyn Error + Send + Sync>>

Examples found in repository?
examples/channel.rs (line 70)
5async fn main() {
6    pretty_env_logger::init();
7
8    let token = std::fs::read_to_string("token.txt").unwrap();
9
10    let client = RestClient::connect(token, None, None).await.unwrap();
11
12    println!("API Version: {}", client.api_version);
13
14    let guild_id: u64 = 1154763102554951811;
15
16    let channel = ChannelBuilder::default()
17        .name("test-channel")
18        .build()
19        .unwrap();
20
21    let mut channel = client
22        .guild(Some(guild_id))
23        .channel(None)
24        .unwrap()
25        .create(channel)
26        .await
27        .unwrap();
28
29    let channel_id = channel.id;
30    println!("Channel ID: {}", channel_id);
31
32    tokio::time::sleep(std::time::Duration::from_secs(1)).await;
33
34    channel.name = Some("test-channel-edited".to_string());
35
36    client
37        .guild(Some(guild_id))
38        .channel(None)
39        .unwrap()
40        .edit(channel)
41        .await
42        .unwrap();
43    let invite = client
44        .guild(Some(guild_id))
45        .channel(Some(channel_id))
46        .unwrap()
47        .create_invite(Default::default())
48        .await
49        .unwrap();
50
51    println!("Invite: discord.gg/{}", invite.code);
52
53    let invite_count = client
54        .guild(Some(guild_id))
55        .channel(Some(channel_id))
56        .unwrap()
57        .get_invites()
58        .await
59        .unwrap()
60        .len();
61
62    println!("Invite count: {}", invite_count);
63
64    tokio::time::sleep(std::time::Duration::from_secs(1)).await;
65
66    client
67        .guild(Some(guild_id))
68        .channel(Some(channel_id))
69        .unwrap()
70        .delete()
71        .await
72        .unwrap();
73}
Source

pub async fn create_invite( &self, create_channel_invite: CreateChannelInvite, ) -> Result<Invite, Box<dyn Error + Send + Sync>>

Examples found in repository?
examples/channel.rs (line 47)
5async fn main() {
6    pretty_env_logger::init();
7
8    let token = std::fs::read_to_string("token.txt").unwrap();
9
10    let client = RestClient::connect(token, None, None).await.unwrap();
11
12    println!("API Version: {}", client.api_version);
13
14    let guild_id: u64 = 1154763102554951811;
15
16    let channel = ChannelBuilder::default()
17        .name("test-channel")
18        .build()
19        .unwrap();
20
21    let mut channel = client
22        .guild(Some(guild_id))
23        .channel(None)
24        .unwrap()
25        .create(channel)
26        .await
27        .unwrap();
28
29    let channel_id = channel.id;
30    println!("Channel ID: {}", channel_id);
31
32    tokio::time::sleep(std::time::Duration::from_secs(1)).await;
33
34    channel.name = Some("test-channel-edited".to_string());
35
36    client
37        .guild(Some(guild_id))
38        .channel(None)
39        .unwrap()
40        .edit(channel)
41        .await
42        .unwrap();
43    let invite = client
44        .guild(Some(guild_id))
45        .channel(Some(channel_id))
46        .unwrap()
47        .create_invite(Default::default())
48        .await
49        .unwrap();
50
51    println!("Invite: discord.gg/{}", invite.code);
52
53    let invite_count = client
54        .guild(Some(guild_id))
55        .channel(Some(channel_id))
56        .unwrap()
57        .get_invites()
58        .await
59        .unwrap()
60        .len();
61
62    println!("Invite count: {}", invite_count);
63
64    tokio::time::sleep(std::time::Duration::from_secs(1)).await;
65
66    client
67        .guild(Some(guild_id))
68        .channel(Some(channel_id))
69        .unwrap()
70        .delete()
71        .await
72        .unwrap();
73}
Source

pub async fn get_invites( &self, ) -> Result<Vec<Invite>, Box<dyn Error + Send + Sync>>

Examples found in repository?
examples/channel.rs (line 57)
5async fn main() {
6    pretty_env_logger::init();
7
8    let token = std::fs::read_to_string("token.txt").unwrap();
9
10    let client = RestClient::connect(token, None, None).await.unwrap();
11
12    println!("API Version: {}", client.api_version);
13
14    let guild_id: u64 = 1154763102554951811;
15
16    let channel = ChannelBuilder::default()
17        .name("test-channel")
18        .build()
19        .unwrap();
20
21    let mut channel = client
22        .guild(Some(guild_id))
23        .channel(None)
24        .unwrap()
25        .create(channel)
26        .await
27        .unwrap();
28
29    let channel_id = channel.id;
30    println!("Channel ID: {}", channel_id);
31
32    tokio::time::sleep(std::time::Duration::from_secs(1)).await;
33
34    channel.name = Some("test-channel-edited".to_string());
35
36    client
37        .guild(Some(guild_id))
38        .channel(None)
39        .unwrap()
40        .edit(channel)
41        .await
42        .unwrap();
43    let invite = client
44        .guild(Some(guild_id))
45        .channel(Some(channel_id))
46        .unwrap()
47        .create_invite(Default::default())
48        .await
49        .unwrap();
50
51    println!("Invite: discord.gg/{}", invite.code);
52
53    let invite_count = client
54        .guild(Some(guild_id))
55        .channel(Some(channel_id))
56        .unwrap()
57        .get_invites()
58        .await
59        .unwrap()
60        .len();
61
62    println!("Invite count: {}", invite_count);
63
64    tokio::time::sleep(std::time::Duration::from_secs(1)).await;
65
66    client
67        .guild(Some(guild_id))
68        .channel(Some(channel_id))
69        .unwrap()
70        .delete()
71        .await
72        .unwrap();
73}

Auto Trait Implementations§

§

impl<'a> Freeze for ChannelRest<'a>

§

impl<'a> !RefUnwindSafe for ChannelRest<'a>

§

impl<'a> Send for ChannelRest<'a>

§

impl<'a> Sync for ChannelRest<'a>

§

impl<'a> Unpin for ChannelRest<'a>

§

impl<'a> !UnwindSafe for ChannelRest<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T