Welcome Webhooks & Member Role | Discord.JS V13 Series | #6

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right so we're gonna go ahead over events folder we're gonna create a new folder and we're gonna call it member for member events and we're gonna create a file and we're gonna call it dial member add dojs for the guild member add events now he will open up accounts and will require discord.js so we can or it can auto complete whatever we need so what we're going to be needing is message embed then we're going to be needing webhook clients just like this and then guide ma remember just for the parameters all right so now here we're gonna model dot exports the name of the event is obviously gonna be guide member add and if we spell it wrong our event handler will automatically validate the name so no problem by the way we're using the event and command handler that we created in the last few episodes i can link them in in the video if you want click up to the right on the card to watch them either way let's continue here we execute we're going to execute the guide or we can actually remember and client and then we can open up a code block or actually we can remove that line because we're not going to be using the client at all actually so let's create our parameters so guild member for this member parameter um just so we can also complete for example member dot user for example if you didn't have the parameters let's remove them oops let's remove them like this now you will see that it will not autofill whatever alright so now that you learned something um here we'll grab a couple of objects from the member object so we're gonna type const user dialed equal member that's how we instead of typing member.guild or member.user we can just grab these objects from the member object all right here if you want to add a rule so for example if it goes ahead to our discord let's go to the entrance channel you see whenever somebody joins the server they both automatically assign them the members role so it's pretty simple you go to your settings to your roles go wherever to that to the member role that you want to assign copy the id of it we're going to go to the visual cd code and here we're going to type member dot roles dot add and here we'll pass in the id now later on in the episodes we're going to be transforming our guide slash commands or guidebot to a public bot we're going to be changing the ids to be database database stored either way so here now we're going to have cons welcomer equals new webhook client so we're creating a new web web hook client we can open this round the brackets then clearly and the idea of how to get the id of the web hook for example um let's go to the entrance channel this is your welcome channel go to integrations web hooks and here you can create a new web hook now i don't need to create a new workbook because already just simple new effort select names in picture anyway you're gonna go over here and you're gonna copy webhook url i'm gonna be changing this after the episode because whoever has your web hook url can basically send whatever they want either way so let's paste the id or the link over here so if you see these numbers after the webhook slash this is the id now we're gonna put a comma and we're gonna type token actually let's put this inside of a string so it's not just standing there right so the token is after the id slash so after this slash you will see the token so let's copy that and place the token inside of the string now we have created and connected uh this web workbook line to the webhook intended so here we're going to create the embed so let's say you want an embed looking like this like mine for example it's pretty slick you're going to have cons welcome sorry equals new message embed right and we're going to set the color of it you can set it to be whatever you want i'll call let's take out for example now here we're going to set the author first of all the author is going to be user dot tag now you see we didn't have member dot user. because we already required the user object from the member so this is this way you can simplify your code then here we're going to type user dot avatar url and it needs to be dynamic set to true and the size you need to input which is going to be 512 or whatever all right so here we're going to set the thumbnail the thumbnail with it which is this over here the picture of that number and so we're going to type that thumbnail and it's going to be user or why bother we can just copy this and paste it over here and here we have our thumbnail now here we're going to set the description all right we're going to start with back this let's open up this paste to simplify it we're going to have welcome you can attack the member or they won't get tagged because it's inside of an embed to that we can make the guide name bold so we're gonna type guide dot sorry guy dot name all right you see we didn't have a member.guild because we already grabbed the guide from the member all right uh here we're gonna create a new line put uh or open a new line i'm gonna type account created this bracket uh t and here we're gonna type percent and inside of the brackets we'll type user created timestamp divided by 1000 because it's in milliseconds and now here we put these and r and this brackets right here we're gonna type or we can open a new line and type the latest member count and we're gonna make it bold and we're gonna type oops my keyboard we're going to type let's see guild.member count once that's done you can set the footer to be the id of that user or the member so set footer id uh we can type actually let's do this so id equals two and let's put the brackets just like this all right and uh it's pretty simple now we're gonna type welcomer dot send embeds and we're going to provide the welcome over here all right so now that's uh we're pretty much done with the our event so do we really need to wait for another member to join us to test it no this code has something called client.emits i'm gonna show you a bonus command in this video we're gonna go to the commands developer we're gonna type emit.js again model.x sorry model.exports uh or before before we can do that we can actually grab the parameters um [Music] so let's go ahead and do that we're gonna grab let's open up a conest require discord hopefully i will come out with a snippet extension so we can stop bothering with this interaction and the client and now here you're gonna model those exports name is going to be mid description emits or type event emitter uh and uh permission it needs to be on administrator uh and now here options inside of an array we're gonna type member for the member events remember uh description guide number events sorry if i'm typing too fast you can pause the video the type of it's going to be string don't forget your commas right um required because it's only one it's going to be required so let's set it to true excuse me so required is going to be set to true because it's it's going to be the only option later on we'll add more we can remove the requirements so choices here we're going to have choices inside of an array name is going to be guild number add value is going to be guide member add then we're going to create a new option or choice and it's going to be remove and guide member remove instead of add so now that we have set up our command structure we gotta go down and here we're gonna execute interaction and client because we're going to be using the clients then we can grab our parameters so command direction and client now here we go we can switch cases so uh first we grab the choices so const choice or show is equals to interaction.options.getstring we're gonna get it from the member because it's the only option that we have currently and now here we're gonna type switch we're gonna make a switch function or statement uh choices and case guide member add then we're gonna execute what inside of this code block so it's gonna be client dot emit guide sorry guide member add and here we're gonna pass in the interaction dot member so we can emit as us that's joined the server or left the server we're going to type regression reply uh content emitted the event and then we can make it a thermal so it's hidden [Music] thermal set to true and now we can copy this or actually let's go down here and break we can copy and paste this break and the only thing that we need to remove is uh change is the guide member add we gotta remember remove and this should be it for our emitter all right so let's try it out let's try out this command an event no herbs we go to the discord now and let's say all right now i'm gonna type emit guide member ad and like you see here the webhook sent a message welcome next to the community account created three years latest member account undefined what is this let's go to our event dialed member account sorry not that member so now let's try it uh event guide member add now he received 490 members let's delete this this two and this two all right so now for our member guide member remove we can simply copy this create a new file call it guide member remove dot js paste it we can remove this we don't need it and for the web hook we're going to change it so let's say you have a member lock channel let's create a channel real quick all right we're going to go into the channel integration create webhook uh hello whatever save generators and here we're going to copy it we're going to paste it over here take the id of it paste it here take the token and paste it here and that should be it instead of world commerce is going to be logger whatever we can change the welcome over here and here we can change the color to be red and here we're going to type um member let's let's remove all of this actually let's just change this member has left the community and here we're going to type joined and instead of user created timestamp we're going to type member dot joined timestamp and this should be it so now let's restart our boat no errors right so let's go here and type emit guide member remove oh nothing happened let's see why oh because it's we didn't change the name of the event so let's change it to remove sorry boys and all right so let's try out that command again so emit remove and like you see here lakes has left a community joined a year ago latest member account it's pretty simple you can do a lot of this this is only example of how to use webhooks and create or send a welcome message or a leave message you can do whatever you want from here for example let's go to our coach here this member here golden ratier took our code from the status command and created his own version of it which is pretty neat so shout out to golden and yeah hope you join the discord if you want support and hope to see you in the next episode
Info
Channel: Lyxcode
Views: 2,898
Rating: undefined out of 5
Keywords: Discord, Discord Bot, Discord.JS, Discord.JS V13, Lyxcode, Discord.JS V13 Bot, How to create a discord bot, Create discord bot, bot, node.js, start bot project, discord bot tutorials, discord.js tutorials, discord.js bot series, discord, discord bot, welcome message, auto member role, webooks, discord.js v13 webhooks
Id: R9T6BKh8h6A
Channel Id: undefined
Length: 13min 11sec (791 seconds)
Published: Tue Sep 28 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.