Rust_Discord_API/utils/
poll.rs1use reqwest::Client;
2use serde_json::Value;
3use std::error::Error;
4
5#[allow(dead_code)]
6pub async fn get_answer_voters(client: &Client, token: &str, channel_id: &str, message_id: &str, answer_id: &str, after: Option<&str>, limit: Option<u32>) -> Result<Value, Box<dyn Error>> {
22 let mut url = format!("https://discord.com/api/v9/channels/{}/polls/{}/answers/{}/voters", channel_id, message_id, answer_id);
23
24 if after.is_some() || limit.is_some() {
25 url.push('?');
26 if let Some(after) = after {
27 url.push_str(&format!("after={}&", after));
28 }
29 if let Some(limit) = limit {
30 url.push_str(&format!("limit={}&", limit));
31 }
32 url.pop(); }
34
35 let response: Value = client.get(&url)
36 .bearer_auth(token)
37 .send()
38 .await?
39 .json()
40 .await?;
41
42 Ok(response)
43}
44
45#[allow(dead_code)]
46pub async fn end_poll(client: &Client, token: &str, channel_id: &str, message_id: &str) -> Result<Value, Box<dyn Error>> {
59 let url = format!("https://discord.com/api/v9/channels/{}/polls/{}/expire", channel_id, message_id);
60 let response: Value = client.post(&url)
61 .bearer_auth(token)
62 .send()
63 .await?
64 .json()
65 .await?;
66
67 Ok(response)
68}