#93 Premium System (with MONGODB) | discord.js tutorials

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome back to discord.js tutorials in today's video i'll be showing you guys how to make a premium system so this command has been i mean this system has been requested tons and tons of time in my discord server so if you would like to give a suggestion for the next video feel free to join the discord server links will be in the description okay so before we start um i would just like to remind you that you need mongodb to make this command or this system so if you don't have mongodb set up you should see a card profile on the right top right of your screen just click on that and um just set mongodb up without further ado let's get right into it all right so for the first part um just create or let me just close okay just just create a model so i'm just going to name this premium ojs okay cons uh model on my own recon because require mongoose module.exports equals to m.model premium [Music] and then i can do something like am on new schema okay so we're gonna just save the users uh we're just gonna save the altruist id so we're just gonna do this so just i'm the model new schema just user this user nothing else all right so there's all for the schema so let me just keep that intact um next we're going to move on to commands okay let me just create a new folder so we can uh actually uh navigate our commands easily so we can find where our command is so let me just do um at premium so this command is basically uh adding a premium membership to a user so we can first we need to uh get the premium schema so it's going to do cost premium schema because require another slider slash models slash premium all right next i'm just going to use this djs code snippet all right so this is premium okay so make sure just to uh quickly grab your own i mean your alters id just get your id real quick so just um okay just get that id so first you want to check if you are the one who is running this command so you can just do if uh message the alternate id it's not equals to this i'm just gonna do return all right so next uh we're gonna do we're gonna define user so called user equal message dimensions the users the first or message.kill as you can use this member so it's going to be the same let me just change this remember member members the first and the message.q members.hatch.get remembers the question again um zero all right so here after that we're gonna check if there is no member return message.reply please specify a valid member okay so once it's specified we're gonna go to start uh we're gonna search in our database by doing premium schema go find one okay i'm gonna find for user which is message which is um user member the id okay next we're going to async error data if error if there is no data let's just do if uh if there is data return message to reply this user has already gained premium features so this is if um the person already has on the date this data is already in the database so we're just going to reply with this user already gain the premium feature so next if the data doesn't exist we're going to create a new data by doing new premium schema and then uh we can just pass in user it'll be use a member id okay and then make sure to add a dot save after the new and then yeah you can just do return message i reply we can do something like added added and user to the database okay so this is the basic setup for at premium uh let me just change this to add all right so for the next one we're going to do the same thing but for remove premium so something like remove let me just use dell premium basically delete premium but it's just like in a abbreviation form all right so um just copy and paste this in here we're gonna change a little uh some stuff no and then um we can do let me see all right so this is all correct okay next in here okay so let me just remove all of these all right so after previous feature uh we're gonna find for a database if there is no data so if there is no data return message to reply um we can just say user was previously not added to database or something like that you can write whatever you want okay and if there's data we're gonna delete the data by doing data.delete and then we can do message.channel send uh delete a removed user from database that's all all right so next we're gonna move on to the message event so we're gonna handle the um we're gonna check if the command is a premium command so let me just search my message.js perfect so uh same thing we're going to require the schema so const um premium schema because require the slash i think zoro slash models slash premium is it let me just check the folder structure um yep it's okay so we can move on uh let me just find all right so in let me just do it after the blacklist okay so if the blacklist and then we're just going to if command dot premium and let me ask you a exclamation mark bracket await a premium schema dot find one and a minimum bracket and then we're going to find the message to auto id message the altered id all right so if it's not a if it's a premium command and the person is not a premium member we can just do return message.reply um let me just space it down so you guys can see it return message to reply and then we can just write something like um you need pre to upgrade to premium to use this command all right okay so let me just teach you guys how to add a command as a premium command so simply let me just go to my ping command because let's say that's the easiest command i'm pretty sure it's in info yep it's a ping ping.js so in here if you want to make a command premium simply just do in here just do premium and then just make it true okay if you don't want it to be premium simply just remove this all right so let's just test this out all right so let's just start the bot up no dot all right so now the bot is online let's just test out the ping command so if i do ping command right now it should work because there is no premium feature right so let me just change this to premium let me show you premium if i make it a true all right and let me restart the bot all right and then if i run y ping again and just say um you need to upgrade premium to use this command so i'm just going to pull up my discord account let me just add my l account as a premium member so you can do this by add premium and i will ping my out account all right is there any errors user is not defined oh i forgot this isn't user it should remember remember but it should uh add the member to the database already so it doesn't really matter yeah all right so um i should be able to use the y ping command right now okay as you can see here uh it actually works so let me just say i want to remove i'm going to remove the premium membership by doing y dell premium and then when the ping programmer is live removed user from database so if i run yping again it wouldn't work because you need to upgrade to premium to use this command so yeah that should conclude today's video on the premium system if you want to watch more disclosure tutorials stay tuned under the end you see a playlist that you can click on aren't that have a nice day see you next video bye
Info
Channel: reconlx
Views: 5,343
Rating: undefined out of 5
Keywords:
Id: yemZ57qO8qk
Channel Id: undefined
Length: 11min 27sec (687 seconds)
Published: Thu Jun 03 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.