Struct serenity::builder::CreateInvite
source · [−]builder
only.Expand description
A builder to create a RichInvite
for use via GuildChannel::create_invite
.
This is a structured and cleaner way of creating an invite, as all parameters are optional.
Examples
Create an invite with a max age of 3600 seconds and 10 max uses:
struct Handler;
#[serenity::async_trait]
impl EventHandler for Handler {
async fn message(&self, context: Context, msg: Message) {
if msg.content == "!createinvite" {
let channel = match context.cache.guild_channel(msg.channel_id) {
Some(channel) => channel,
None => {
let _ = msg.channel_id.say(&context, "Error creating invite").await;
return;
},
};
let creation =
channel.create_invite(&context, |i| i.max_age(3600).max_uses(10)).await;
let invite = match creation {
Ok(invite) => invite,
Err(why) => {
println!("Err creating invite: {:?}", why);
if let Err(why) =
msg.channel_id.say(&context, "Error creating invite").await
{
println!("Err sending err msg: {:?}", why);
}
return;
},
};
let content = format!("Here's your invite: {}", invite.url());
let _ = msg.channel_id.say(&context, &content).await;
}
}
}
let mut client =
Client::builder("token", GatewayIntents::default()).event_handler(Handler).await?;
client.start().await?;
Tuple Fields
0: HashMap<&'static str, Value>
Implementations
sourceimpl CreateInvite
impl CreateInvite
sourcepub fn max_age(&mut self, max_age: u64) -> &mut Self
pub fn max_age(&mut self, max_age: u64) -> &mut Self
The duration that the invite will be valid for.
Set to 0
for an invite which does not expire after an amount of time.
Defaults to 86400
, or 24 hours.
Examples
Create an invite with a max age of 3600
seconds, or 1 hour:
let invite = channel.create_invite(context, |i| i.max_age(3600)).await?;
sourcepub fn max_uses(&mut self, max_uses: u64) -> &mut Self
pub fn max_uses(&mut self, max_uses: u64) -> &mut Self
The number of uses that the invite will be valid for.
Set to 0
for an invite which does not expire after a number of uses.
Defaults to 0
.
Examples
Create an invite with a max use limit of 5
:
let invite = channel.create_invite(context, |i| i.max_uses(5)).await?;
sourcepub fn temporary(&mut self, temporary: bool) -> &mut Self
pub fn temporary(&mut self, temporary: bool) -> &mut Self
Whether an invite grants a temporary membership.
Defaults to false
.
Examples
Create an invite which is temporary:
let invite = channel.create_invite(context, |i| i.temporary(true)).await?;
sourcepub fn unique(&mut self, unique: bool) -> &mut Self
pub fn unique(&mut self, unique: bool) -> &mut Self
Whether or not to try to reuse a similar invite.
Defaults to false
.
Examples
Create an invite which is unique:
let invite = channel.create_invite(context, |i| i.unique(true)).await?;
sourcepub fn target_type(&mut self, target_type: InviteTargetType) -> &mut Self
pub fn target_type(&mut self, target_type: InviteTargetType) -> &mut Self
The type of target for this voice channel invite.
sourcepub fn target_user_id(&mut self, target_user_id: UserId) -> &mut Self
pub fn target_user_id(&mut self, target_user_id: UserId) -> &mut Self
The ID of the user whose stream to display for this invite, required if target_type
is
Stream
The user must be streaming in the channel.
sourcepub fn target_application_id(
&mut self,
target_application_id: ApplicationId
) -> &mut Self
pub fn target_application_id(
&mut self,
target_application_id: ApplicationId
) -> &mut Self
The ID of the embedded application to open for this invite, required if target_type
is
EmmbeddedApplication
The application must have the EMBEDDED
flag.
When sending an invite with this value, the first user to use the invite will have to click on the URL, that will enable the buttons in the embed.
These are some of the known applications which have the flag:
betrayal: 773336526917861400
youtube: 755600276941176913
fishing: 814288819477020702
poker: 755827207812677713
chess: 832012774040141894
Trait Implementations
sourceimpl Clone for CreateInvite
impl Clone for CreateInvite
sourcefn clone(&self) -> CreateInvite
fn clone(&self) -> CreateInvite
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for CreateInvite
impl Debug for CreateInvite
sourceimpl Default for CreateInvite
impl Default for CreateInvite
sourcefn default() -> CreateInvite
fn default() -> CreateInvite
Creates a builder with default values, setting validate
to null
.
Examples
Create a default CreateInvite
builder:
use serenity::builder::CreateInvite;
let invite_builder = CreateInvite::default();
Auto Trait Implementations
impl RefUnwindSafe for CreateInvite
impl Send for CreateInvite
impl Sync for CreateInvite
impl Unpin for CreateInvite
impl UnwindSafe for CreateInvite
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more