Embeds and Permissions | How to Code a Discord Bot! | Discord.JS v13 Tutorial #4

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everybody welcome back to another discord.js tutorial video today i'm going to be showing you guys how to make embeds and how to use permissions on your commands so the first thing we're going to do is look at uh embeds so i have the official discord.js guide over here you can see here that we've got uh this is what an embed is so what you have is an author here the author can have a link uh a little picture there and some text uh you got a title which will be blue if you have a link and just white if you don't and then that will that will have some text or a link on there and then we've got a description which is just text uh you can put a link on there if you want but uh it's mostly just text you've got a thumbnail which was just a smaller picture uh just a small picture here and then you've got uh what are called fields so field has a title and then a value so you've got a regular field and then inline fields so in light will be all the same light here regular fields will just be like vertical and then you've got just a double image so you can just display an image on there and then a footer with a image on there and you could have a timestamp and a color color so like the color color of your embed so that's basically what an embed is you can have all of these different properties and it's just a nicely formatted uh piece of text so let's go into our code here and let's go ahead and make a new command so embed.js i'm going to show you every single property of an embed and first we're going to do is grab our event class get out of that uh command class acquire dot slash dot slash structures slash command all right now module that exports equals do command in our object here gonna have a name it'll be embed a description shows an embed and a run function uh let you do async run message arcs quiet there we go so in our run function we've got message rx clients so let me just figure out why that's not working discord ah that's right okay i for this is a new folder so i have to install all this but in here we're going to also import discord so we're going to use the embed those require whoops require discord.js and also right before we get into this i just want to uh show something to you so basically if we go back to discord you can see every time we use the reply function on our message we get a reply here but it also pegs us so if you don't want it to pig you uh it just wants to just do a passive reply all i have to do is go to client.js and right here we have our super add a comma and type in uh allowed mentions and then a colon uh an object here we're going to type in replied user called false and that will makes it so that when you reply it won't pig you so if you want that you could add that if you don't you don't need it then you're fine so in here we have our discord library here clear this and we can start with making it embed so i'm going to make a constant embed variable equals a new discord dot message embed in here you can pass it an object for any sort of properties you want like a title or you can pass it another embed or like a json embed but we're going to be using functions here to set everything so we're going to do embed that's set title let's start with the title so a title let's make this this is a test admit in order to send our embed we have to do message that reply also another way to send messages is to channel that send and then that won't reply so if you wanted to just send the message without replying just do that uh but then we could do message reply in here we have our options interaction reply options effect reply true and our message payload so i think it might either it could be an embed or an options that contains the embed edits so let me just try this out not sure if it will work so if we just do exclamation mark embed yeah uh cannot set it empty business yeah so if we do instead it object to edbed is equal to that bed uh i think that'll work then i bet no cannot set it up to message is it embeds equals an array of embeds i bet there we go so what you have to do is do uh an object with embeds in it colon and then an array of embeds so i believe we go back over here setting it in bed yeah that's how they did it uh so yeah if we go over here let's go ahead and add more properties to here so we could get rid of this colon here do we dilide it dead and then we could do another dot let's go ahead and set an author and you can also see in our discord you can see it just has our title in it the color the color is black because we had it we didn't set a color and we could just remove the embed if we want to but there we go that's just a test embed we're gonna set an author here our author is gonna have a name an icon and a url so if you just do message dot author dot username uh we could also do oh by the way i'm just going to go back and command i'm going to remove uh move interaction so it'll just be just for that message that it should have all this stuff in here yeah okay so that icon url you can do message.author.avatar url uh it's a function and we can add in a object here which has dynamic format and size so i'm going to put dynamic it's true [Music] and that a url i'm just going to link my websites https.dev there we go so now if we go ahead and note about this okay go over here do our embed you can see now it replies with an embed that has my name on it and my profile picture and if i click this it will take me to my website so go back into discord we've got our embed here and that's just a author now we can add let's say a description so set description let's add this is some plain text and let's go ahead and add a new line here is a link and in order to make links where it actually has uh a name on the link so let's say we want a link to just say link but actually the link is something other than just play text link what we could do is just uh this is a test link so you open square brackets here you type in the name of the link and then we actually type in the link so if i put my website again then we can see here in our description uh oh it's restarting so [Music] in here let's try this again there we go so you have our play text and a link and you can see that the name of the link is this is a test link but we click on it it goes to my website so that's how you can also do that stuff i believe in titles are like uh and fields i believe and yeah uh also if you want a url on the title what you could do is do stop set url type in the url save it and there we go it has our url on there and click it it's my website okay cool so so [Music] back over here let's add some more properties so what else do we got we've got set color set color we could set this to just any hex color or you can set it to any of these uh default colors that they've got so let's say we want aqua just type it aqua or if you want let's say just white you can do hashtag ffffffffffff or get rid of the string altogether and do zero x and then the other then the uh the hex codes so [Music] any of those options work but you could use some of these the presets are pretty good let's try just using purple which is a mix of blue and purple so if you do embed again you can see that the color is now blue and purple so it's purple but now if we add another dot we could add fields or let's see what else should i put first uh let's do set a thumbnail so dot set thumbnail and we're just going to do of the bot so let's do client.user.avatar url dynamic true i'm not entirely sure what that ivec does but we could go ahead and check the docs here so avatar that's a guide we want discord.js.org for our documentation we are going to find user and avatar url and here we go image url options dynamic if true the format will dynamically change to gif for animated avatars that that's what that does all right so yeah if your avatar is a gif that you can use uh that'll just display it as a gift so and here collect the user to avatar url dynamic true you save that go back to discord you can see that wasn't ready bed uh why is it not showing up no it just doesn't want to show it all right oh yeah it's cause the that's right because the avatar of the bot is nothing right now so let's just change this back to message.author if we do this again it should work yeah there we go so now it has my thumbnail on there which is just a a slightly larger image than this here we can go ahead and do the dex property which let's see author color created at color the image so we could do a timestamp uh typestep and hit the image and then we can move on to fields so set timestamp what this does is adds a timestamp to the footer of an embed you could uh supply what state you want or if you just leave it blank it'll supply the current date so if you do this again let's just try doing message dot created timestamp for that so it'll be the exact same timestamp as the message let's go back over here at bed you can see now today at 11 33 a.m is when this message was created and it's what the timestamp is but if we were to say subtract let's say an hour from it i believe that's an hour subtract an hour from it that'll say oh wait that was just six minutes okay my bad um so i'll to do add one more zero and then now it's an hour later or an hour earlier so 10 10 8 10 33 a.m so yeah basically what this time time format is is uh udix time so it's just the number of milliseconds since i believe january 1st 1970 uh so yeah that's the type form that discard uses uh for their type stamps and outside their discord or discord.cs i'm not sure but there we go we have our timestamp and let's go ahead and add an image set image let's it has to be a url uh otherwise you'd have to go ahead and go up here to have it use the image from your desktop uh there's some documentation for it i believe so dot set image let's just set i don't know let's set a random image uh discord logo just grab this copy the image address i'm going to paste that there if we go ahead and save it restart it there we go we have our big image here which is just the discord logo and now we can start adding some fields so if you have only one field you can use the add field property or add field function and that will add just the name of the field and the value of this field and that inline so let's start off with the name let's say uh bot and bot version i guess and then our value will put just 1.0.0 and if we want it to be inline let's just make it inline so we just put true it's not going to matter so it's only one field but we do embed there we go so bot version is 1.040 but let's add fields instead and what we do is we can either make an array of objects or just put objects separated by compass in here because it accepts multiple but in here just going to take a dave property which will be a bot version a a uh value property which will be 1.0.0 an inline property which will be true our dachshund uh let's say you spot dave value clients dot user dot uh username it lied true so if you save that restart this you can see here that we have our bot version which is 1.00 which is tutorialbot so that's basically the basics of using an embed with our thing here so i guess it's time to move on to permissions because i believe we got it to every single property of an embed so let's start with permission so enter command class over here we're going to add another thing to our options so in our js doc here right after our description let's add permission and that will be a discord.permission flat key it'll be key of key of discord that provision flags or we could have just added normal string i guess because what we could do is have it so it'll it'll take like a user id or a role id or something like that or old name so now over in here we do this dot uh this dot permission is equal to option step permission and then in all these commands we have to make a permission variable for a permission thing in here and our position for this will just be said messages which usually it would it doesn't uh let's get rid of this maybe pressure is discord permission strike permission string yeah this is what we want so down here do this and that is not what we want oh kiev that's right give it a key of and it should just be there we go all of our permissions here so you can have just send messages and then this will we could have in our message create over here in here we can have it so that we can just grab the permissions of cost permission is equal to uh message.member dot has or what would it be so the member is a guild member and i believe it's just permissions that has and then command that permission and then if no permission can return message shall reply you do not have let's get this you do not have the permission random permission to run this command let's go ahead and just add some actics here for a little bit of formatting and that should be it for permission so if we just go ahead and add this line of text to every single one of these then it should work so embed it still works but that will say oh i'd have to use it alt to make sure this works but i believe this permissions that has let's just check check the docs here or guild lever dark permissions say read all the applications okay permissions has a has property as permission and then check admit so if you turn check admin to true then it will allow the administrator permission to override which most likely you would look you'd want that so you could probably just put comma true there then that would work fine we had our permission and that should be it for this video so uh i believe we got everything so we got our permissions we got our embed and yeah you can start making some embeds of your own so some formatted text and we could go ahead and use permissions on that so we could change the invent command to say let's say band members you need the permission band members to use the command which for which foreign is a little bit strict but uh that's just for an example so that should be it uh i'll see you guys later and i'll see you in the next video which i'll still think about what what i'll do the next video but i'll do that as soon as i can so see you guys
Info
Channel: Ferotiq
Views: 7,483
Rating: undefined out of 5
Keywords: Discord.js, how, to, make, discord, bot, v13, 13, create, code, client, embeds, permissions
Id: RjuPTUAw1rg
Channel Id: undefined
Length: 21min 48sec (1308 seconds)
Published: Tue Aug 10 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.