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

pub struct CreateInvite(pub HashMap<&'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: Context, msg: Message) {
        if msg.content == "!createinvite" {
            let channel = match context.cache.read().guild_channel(msg.channel_id) {
                Some(channel) => channel,
                None => {
                    let _ = msg.channel_id.say(&context, "Error creating invite");
                    return;
                },
            };

            let channel = channel.read();

            let creation = channel.create_invite(&context, |i| {
                i.max_age(3600).max_uses(10)
            });

            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") {
                        println!("Err sending err msg: {:?}", why);
                    }

                    return;
                },
            };

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

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

client.start().unwrap();

Implementations

impl CreateInvite[src]

pub fn max_age(&mut self, max_age: u64) -> &mut Self[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(context, |i| {
    i.max_age(3600)
})?;

pub fn max_uses(&mut self, max_uses: u64) -> &mut Self[src]

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

pub fn temporary(&mut self, temporary: bool) -> &mut Self[src]

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

pub fn unique(&mut self, unique: bool) -> &mut Self[src]

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

Trait Implementations

impl Clone for CreateInvite[src]

impl Debug for CreateInvite[src]

impl Default for CreateInvite[src]

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

Auto Trait Implementations

Blanket Implementations

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

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

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

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

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

impl<T> From<T> for T[src]

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

impl<T> Same<T> for T

type Output = T

Should always be Self

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

type Owned = T

The resulting type after obtaining ownership.

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

type Error = Infallible

The type returned in the event of a conversion error.

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

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> UnsafeAny for T where
    T: Any

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,