#How to get started with Monetization in Discord.NET?

1 messages · Page 1 of 1 (latest)

earnest brook
#

I wanted to ask how I could get started with implementing paid features into my bot via Discords default monetization stuff, how can i make premium only commands, check if a user has the premium thing and also get notified if a user has gotten it (if possible)

gray aspen
#

you will have to connect to a database.

earnest brook
gray aspen
#

Or, you can give a role to a user

earnest brook
#

but i need a way to know what user has it and who doesnt

gray aspen
#

if the paiement is valid

earnest brook
#

bot can be on any server

gray aspen
#

what do you mean by default discord monetization ?

earnest brook
#

i have no prior experience with this so idk how to implement it

gray aspen
#

where do you find it ?

earnest brook
#

in the developer panel of my bot

gray aspen
#

ok

#

let me check

earnest brook
#

cant see more info abt it rn cause thats stuff i wanna do after i got a stable version of it

gray aspen
#

I'm not sure Discord.NET has wrapped this monetization part of the api

#

And i think this is not the behaviour you want

earnest brook
#

wym

gray aspen
#

It's to make server owner paid to integrate your bot in their server

#

You can't make each user of the server pay to use the bot

#

You'll have to integrate a payment gateway within your bot

#

like paypal or stripe

earnest brook
gray aspen
#

Ok nevermind then

earnest brook
#

if an admin buys it the whole server gets it apparently

#

nvm thats a guild subscription thats another thing

gray aspen
#

yes

earnest brook
#

ig they can choose then

#

fine by me honestly

gray aspen
#

i can find the state

#

but nothing more

#

@earnest brook

earnest brook
#

perfect

#

thanks!

gray aspen
#

np

left mantle
#

Yeah so we definitely need to write guides on monetization (I was going to do this , oops) BUT the library support is definitely here.

#

you will have to do a few things to handle "entitlements"

#
Client.EntitlementCreated += EntitlementCreated;
Client.EntitlementDeleted += EntitlementDeleted;
Client.EntitlementUpdated += EntitlementUpdated;
#

the EntitlementCreated and EntitlementUpdated are the most important

#

this is where you would handle giving a user premium.

earnest brook
left mantle
#

gimme a sec

earnest brook
#

a feature where you could restrict certain interactions to an SKU would be cool for Discord.NET

left mantle
#

tbh idk

#

BUT

#

you can check it in an interaction

#

Context.Interaction.Entitlements in a command for exmaple

earnest brook
#

tysm!

left mantle
#
public static bool IsPremium(IReadOnlyCollection<RestEntitlement> entitlements)
{
  return entitlements.Count > 0 && entitlements.FirstOrDefault(x => x.SkuId == 1169107771673812992) is not null;
}

something like this

earnest brook
#

yas

left mantle
#

except obviously ur skuid

left mantle
#

You figure this out?

earnest brook
# left mantle You figure this out?

ill implement it in a few days or hours depending on when i next want to work on the bot, i dont want to release it and instantly add a feature for monetization when there are some bugs to fix
ill respond to you when i start implementing this and or have my first results tho

#

also for testing, will discord allow me to purchase my own SKU for free sort of like a debug or do i actually have to buy it

left mantle
#

Yes you can do it for free

left mantle
#

Something i did was start a second instant of the bot and not accept commands on it just premium stuff for testing

earnest brook
#

Also is it even important to store entitlements since discord seems to send them on every interaction anyways?

left mantle
#

so you need to handle the entitlement events but not interaction received or created or stuff like thatr

earnest brook
#

Ah

left mantle
earnest brook
#

I mean I should save them if I'm adding stuff like a dashboard for them or a special role or something since that's data I don't change or check on every interaction like I can't set that role only for then etc
But I think I'd be fine currently with just checking each interaction since I don't give the users any special role atm cause of how the bot is built

left mantle
#

I mean whatever works for you

earnest brook
#

Even if shit hits the fan I'll make sure to always have an easy way for users to submit a feedback form

earnest brook
# left mantle I mean whatever works for you

so im now working with Entitlements and i have a few questions

  • how can i test this
  • how can i properly write a handler for consumable entitlements and subscriptions, since i saw that the SocketClient has a function called ConsumeEntitlement but i dont understand it
left mantle
#

So depends on what you wanna test but you can go about it a few ways.

earnest brook
#

i figured it out
had to enable app test mode

#

writing my handler atm
for one time purchases i just need to handle it and consume it for subs discord will send me the entitlement

left mantle
#

essentially

#

personally I have never used the app test mode I just made a seconds instance of my bot and then only had the premium commands being tested deployed from that instance

earnest brook
#

its pretty cool

#

you can buy stuff from your app and wont get charged

left mantle
#

I thought you could always buy stuff from your app and not be charged

earnest brook
#

i wrote an extension method for my User object called IsPremium now i can check the object directly