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

pub struct CreateInvite(pub VecMap<&'static str, Value>);

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;

impl EventHandler for Handler {
    fn message(&self, _: Context, msg: Message) {
        use serenity::CACHE;
        if msg.content == "!createinvite" {
            let channel = match CACHE.read().guild_channel(msg.channel_id) {
                Some(channel) => channel,
                None => {
                    let _ = msg.channel_id.say("Error creating invite");

                    return;
                },
            };

            let reader = channel.read();

            let invite = match reader.create_invite(|i| i.max_age(3600).max_uses(10)) {
                Ok(invite) => invite,
                Err(why) => {
                    println!("Err creating invite: {:?}", why);

                    if let Err(why) = msg.channel_id.say("Error creating invite") {
                        println!("Err sending err msg: {:?}", why);
                    }

                    return;
                },
            };

            drop(reader);

            let content = format!("Here's your invite: {}", invite.url());
            let _ = msg.channel_id.say(&content);
        }
    }
}

let mut client = Client::new("token", Handler).unwrap();

client.start().unwrap();

Methods

impl CreateInvite
[src]

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(|i| i.max_age(3600))?;

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(|i| i.max_uses(5))?;

Whether an invite grants a temporary membership.

Defaults to false.

Examples

Create an invite which is temporary:

let invite = channel.create_invite(|i| i.temporary(true))?;

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(|i| i.unique(true))?;

Trait Implementations

impl Default for CreateInvite
[src]

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();

impl Clone for CreateInvite
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for CreateInvite
[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

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

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

recently added

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

impl<T> From for T
[src]

Performs the conversion.

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T> Borrow for T where
    T: ?Sized
[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut for T where
    T: ?Sized
[src]

Mutably borrows from an owned value. Read more

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

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

this method will likely be replaced by an associated static

Gets the TypeId of self. Read more

impl<T> Erased for T

impl<T> Typeable for T where
    T: Any

Get the TypeId of this object.

impl<T> DebugAny for T where
    T: Any + Debug
[src]

impl<T> CloneAny for T where
    T: Clone + Any
[src]

impl<T> UnsafeAny for T where
    T: Any