Struct serenity::builder::CreateInvite[][src]

pub struct CreateInvite(pub HashMap<&'static str, Value>);
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).await {
                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").event_handler(Handler).await?;

client.start().await?;

Tuple Fields

0: HashMap<&'static str, Value>

Implementations

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?;

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?;

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?;

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?;

The type of target for this voice channel invite.

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.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more