#Premium guild subscription check

1 messages · Page 1 of 1 (latest)

neon abyss
#

How to check if a server has premium subscription ?

shadow citrus
swift torrentBOT
neon abyss
#

Its with discord.Interaction attribute ?

#

not with Guild ?

swift torrentBOT
shadow citrus
#

Oh

#

I think it's guild.entitlements for server subs then

neon abyss
#

Or how to get it without await or async for ?

shadow citrus
#

Uhh, not sure

#

@potent thicket

neon abyss
#

Or just a guild.get_entitlement(ID) or something like that

snow fulcrum
neon abyss
snow fulcrum
#

I am trying to fetch it

neon abyss
#

yes

#

with the sku_id

snow fulcrum
# neon abyss with the sku_id

but it does not tell you if the server paid for it, I got the exactly same result for a server that pay, and for another that does not pay

neon abyss
snow fulcrum
#

yes ```py
guild_entitlements = ctx.guild.entitlements(skus=[complete_sku], exclude_ended=True)
print(complete_sku.id in guild_entitlements.sku_ids)

neon abyss
#

my code is under development thanks for warning me 😅

snow fulcrum
neon abyss
#

xD

snow fulcrum
#

So currently I don't think there is any way to get the status of a server subscription on the bot except if we store it in a database

neon abyss
snow fulcrum
neon abyss
#

remove the argument in entitlements

#

and print just the complete_sku

snow fulcrum
# neon abyss and print just the complete_sku

complete_sku is the SKU object of what I want to check the server has.
if I just leave the ctx.guild.entitlements clear, I have an object full of None but my server has the subscription.
It does not tell if the server have paid in the shop for it

neon abyss
#

@potent thicket you know how to check if a server is premium ?

shadow citrus
snow fulcrum
shadow citrus
#

Then I was wrong and don't mind me lol

prime atlas
#

as per the examples (you can use guild instead of client/user)

snow fulcrum
#

thanks !!
The flatten() method did not work for me but the async for loop worked

neon abyss
#

No one know how to check if a server is premium ?

snow fulcrum
neon abyss
snow fulcrum
neon abyss
snow fulcrum
# neon abyss He just not say I don't have premium

did you try something like this ?

        if self.bot.premium_sku is None:
            SKUS = await self.bot.fetch_skus()
            for SKU in SKUS:
                if SKU.name == "Unlock Premium Features":
                    self.bot.premium_sku = SKU
                    break
        
        if self.bot.premium_sku.id not in [entitlement.sku_id async for entitlement in ctx.guild.entitlements()]:
...
snow fulcrum
#

this code works for me

neon abyss
#
if PREMIUM_SKU is None:
        SKUS = await bot_ins.fetch_skus()
        for SKU in SKUS:
            print(SKU)
            print(SKU.id)
            if "AwaBot Premium" in SKU.name:
                PREMIUM_SKU = SKU
                break
    
    if PREMIUM_SKU is None:
        return False
    async for entitlement in entitlements:
        print(entitlement.sku_id)
    if PREMIUM_SKU.id not in [entitlement.sku_id async for entitlement in entitlements]:
        return False
    
    return True

print =>
Entitlement:
1286039387246694430
1286039387246694430

Premium_sku =>
AwaBot Premium
1285648183673880576

snow fulcrum
neon abyss
#

the async for's print ?

snow fulcrum
#

yes

neon abyss
#
1286039387246694430
1286039387246694430
snow fulcrum
neon abyss
#

its a function

snow fulcrum
#

uh ? show me your function then

neon abyss
#
async def is_premium(bot_ins, guild):
    global PREMIUM_SKU
    
    if not guild:
        return False
    
    if isinstance(guild, discord.Guild):
        entitlements = guild.entitlements()
    else:
        guild_ins = bot_ins.get_guild(guild)
        if not guild_ins:
            return False
        entitlements = guild_ins.entitlements()
    
    if PREMIUM_SKU is None:
        SKUS = await bot_ins.fetch_skus()
        for SKU in SKUS:
            print(SKU)
            print(SKU.id)
            if "AwaBot Premium" in SKU.name:
                PREMIUM_SKU = SKU
                break
    
    if PREMIUM_SKU is None:
        return False
    async for entitlement in entitlements:
        print(entitlement.sku_id)
    if PREMIUM_SKU.id not in [entitlement.sku_id async for entitlement in entitlements]:
        return False
    
    return True
snow fulcrum
neon abyss
#

AwaBot Premium

snow fulcrum
#

I mean... of the ones you said, the SKU with ID 1286039387246694430

neon abyss
#

ok but why this debug return 1285648183673880576

snow fulcrum
neon abyss
#

This debug

snow fulcrum
#

replace entitlement.sku_id by entitlement.name

neon abyss
#

discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: AttributeError: 'Entitlement' object has no attribute 'name'

snow fulcrum
neon abyss
#

AwaBot Premium

snow fulcrum
# neon abyss

are you sure the sku id is the one that finishes by 30 like I have put in the link ?

neon abyss
snow fulcrum
#

do the same with the 1285648183673880576 now

neon abyss
snow fulcrum
#

weird

snow fulcrum
neon abyss
snow fulcrum
#

not for me, that's weird