pub struct WebhookClient { /* private fields */ }Expand description
A webhook used through its ID and token, without a bot token or a gateway connection: sending messages to a channel from a script, a CI job or a server.
The token is the webhook’s password: keep it out of logs and repositories. Debug
redacts it.
discord.js counterpart: WebhookClient.
Implementations§
Source§impl WebhookClient
impl WebhookClient
Sourcepub fn new(id: WebhookId, token: impl Into<String>) -> Self
pub fn new(id: WebhookId, token: impl Into<String>) -> Self
A client for the webhook id with its token.
discord.js counterpart: new WebhookClient({ id, token }).
Sourcepub fn from_url(url: &str) -> Result<Self, InvalidWebhookUrl>
pub fn from_url(url: &str) -> Result<Self, InvalidWebhookUrl>
A client for a webhook URL as Discord shows it,
https://discord.com/api/webhooks/{id}/{token} (D-241). The discordapp.com, canary.
and ptb. hosts and a versioned path (/api/v10/webhooks/…) are accepted too; a query
string is ignored.
discord.js counterpart: new WebhookClient({ url }).
§Errors
Returns InvalidWebhookUrl if url is not a Discord webhook URL.
§Examples
use djs_rs::{WebhookClient, model::id::WebhookId};
let webhook = WebhookClient::from_url("https://discord.com/api/webhooks/123/abc-DEF_9").unwrap();
assert_eq!(webhook.id(), WebhookId::new(123));
assert!(WebhookClient::from_url("https://example.com/api/webhooks/123/abc").is_err());Sourcepub fn rest(self, rest: Rest) -> Self
pub fn rest(self, rest: Rest) -> Self
Sends the requests through rest instead of a default client, for example one with a
proxy or another API base. A bot token it holds is not sent: webhook routes are
authorized by the webhook’s token.
discord.js counterpart: the rest option of WebhookClientOptions.
Sourcepub const fn id(&self) -> WebhookId
pub const fn id(&self) -> WebhookId
The webhook’s ID.
discord.js counterpart: WebhookClient#id.
Sourcepub fn send(
&self,
body: impl Into<ExecuteWebhook>,
) -> impl Future<Output = Result<Message, Error>> + Send + '_
pub fn send( &self, body: impl Into<ExecuteWebhook>, ) -> impl Future<Output = Result<Message, Error>> + Send + '_
Sends a message (Execute Webhook, waiting
for the message); accepts anything that converts into an ExecuteWebhook, such as
&str.
discord.js counterpart: WebhookClient#send.
§Errors
Returns the REST error if the request failed.
Sourcepub async fn fetch_message(
&self,
message_id: MessageId,
thread: Option<ChannelId>,
) -> Result<Message, Error>
pub async fn fetch_message( &self, message_id: MessageId, thread: Option<ChannelId>, ) -> Result<Message, Error>
A message the webhook sent (thread for one in a thread).
discord.js counterpart: WebhookClient#fetchMessage.
§Errors
Returns the REST error if the request failed.
Sourcepub async fn edit_message(
&self,
message_id: MessageId,
body: &EditWebhookMessage,
) -> Result<Message, Error>
pub async fn edit_message( &self, message_id: MessageId, body: &EditWebhookMessage, ) -> Result<Message, Error>
Edits a message the webhook sent.
discord.js counterpart: WebhookClient#editMessage.
§Errors
Returns the REST error if the request failed.
Sourcepub async fn delete_message(
&self,
message_id: MessageId,
thread: Option<ChannelId>,
) -> Result<(), Error>
pub async fn delete_message( &self, message_id: MessageId, thread: Option<ChannelId>, ) -> Result<(), Error>
Deletes a message the webhook sent (thread for one in a thread).
discord.js counterpart: WebhookClient#deleteMessage.
§Errors
Returns the REST error if the request failed.
Sourcepub async fn fetch(&self) -> Result<Webhook, Error>
pub async fn fetch(&self) -> Result<Webhook, Error>
The webhook itself (Get Webhook with Token).
discord.js counterpart: none (WebhookClient cannot fetch its webhook; Client#fetchWebhook can).
§Errors
Returns the REST error if the request failed.
Trait Implementations§
Source§impl Clone for WebhookClient
impl Clone for WebhookClient
Auto Trait Implementations§
impl !RefUnwindSafe for WebhookClient
impl !UnwindSafe for WebhookClient
impl Freeze for WebhookClient
impl Send for WebhookClient
impl Sync for WebhookClient
impl Unpin for WebhookClient
impl UnsafeUnpin for WebhookClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Classify for T
impl<T> Classify for T
type Classified = T
fn classify(self) -> T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Declassify for T
impl<T> Declassify for T
type Declassified = T
fn declassify(self) -> T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more