#Check if a User has Premium.

1 messages · Page 1 of 1 (latest)

winter hare
#

How can I determine if a user has premium?

jovial pendant
#

Premium in what way

#

A custom premium thing or an official discord thing

winter hare
#

Discord bot SKUs

winter hare
#

and/or entitlements

winter hare
#

My issue is that, if people subscribed before I added SKU entitlement handling how can I know if a user has premium?

cunning otter
#

Something like

public static bool IsPremium(IReadOnlyCollection<RestEntitlement> entitlements)
    {
        return entitlements.Count > 0 && entitlements.FirstOrDefault(x => x.SkuId == 1156298921421852733) is not null;
    }```
should work
#

(Obviously adjust to whatever sku numbers you are looking for)

#

I primarily use the Entitlement event handling to monitor and store new subscriptions in the DB, but I also have this as a fallback for if that ever fails or such

#

I'm unsure if you are able to see a user's entitlements to other bots, if you can only see entitlements to your own bot, then the specific ID check is probably not required (unless you have multiple skus, like user vs server premium or such, plus I think discord plans to allow multiple tiers at some point, so depends on your use case)

winter hare
#

Thanks a bunch!

cunning otter
#

Np 🙂

winter hare
#

so that I can update my DB?

cunning otter
#

Also not that im aware of

winter hare
#

maybe I am dumb

#

what I mean is so that I can store the expiration date in the DB

cunning otter
#

It's included on the rest entity though

#

Obviously dont just use FirstOrDefault because it could be null, or grab wrong entitlement or such, but the property does exist

winter hare
#

ah okie

#

thanks