1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
use crate::request::prelude::*; use twilight_model::id::{ChannelId, MessageId}; /// Create a reaction in a [`ChannelId`] on a [`MessageId`]. /// /// The reaction must be a variant of [`RequestReactionType`]. /// /// # Examples /// ```rust,no_run /// use twilight_http::{Client, request::channel::reaction::RequestReactionType}; /// use twilight_model::{ /// id::{ChannelId, MessageId}, /// }; /// /// # #[tokio::main] /// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> { /// let client = Client::new("my token"); /// /// let channel_id = ChannelId(123); /// let message_id = MessageId(456); /// let emoji = RequestReactionType::Unicode { name: String::from("🌃") }; /// /// let reaction = client /// .create_reaction(channel_id, message_id, emoji) /// .await?; /// # Ok(()) } /// ``` /// /// [`ChannelId`]: ../../../../twilight_model/id/struct.ChannelId.html /// [`MessageId`]: ../../../../twilight_model/id/struct.MessageId.html /// [`RequestReactionType`]: enum.RequestReactionType.html pub struct CreateReaction<'a> { channel_id: ChannelId, emoji: String, fut: Option<Pending<'a, ()>>, http: &'a Client, message_id: MessageId, } impl<'a> CreateReaction<'a> { pub(crate) fn new( http: &'a Client, channel_id: ChannelId, message_id: MessageId, emoji: RequestReactionType, ) -> Self { Self { channel_id, emoji: super::format_emoji(emoji), fut: None, http, message_id, } } fn start(&mut self) -> Result<()> { self.fut.replace(Box::pin(self.http.verify(Request::from( Route::CreateReaction { channel_id: self.channel_id.0, emoji: self.emoji.clone(), message_id: self.message_id.0, }, )))); Ok(()) } } poll_req!(CreateReaction<'_>, ());