Userinfo Command + Context Menu | Discord.JS V13 Series | #9

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this is how your command will be looking like after we're done with the episode so you can select a random member from the server you can right click and then you can select apps and press on that user info command that we created in this episode and it should be looking something like this with an affirmative message that you can dismiss because you are the only one seeing this message so let's go ahead and start out all right so because uh context menus function almost the same as the normal command interaction we're gonna use or utilize our interactioncreate.js file so let's go to the events interaction folder to the interaction create so we're gonna be utilizing the same handler as this one we'll just add a statement so if we go into this tenth line we'll make a space after the s command and in there on the brackets and he will type interaction dot is contest mini with this rounded practice and between two of these will add this or statement so if interaction is command or if the interaction is context menu we'll run this exact same code so it's it's a pretty simple the only big difference between the context menu and the command is you cannot use a description uh you cannot use options and etc so let's go ahead to our commands folder to our utilities category and we'll create a new file we'll call it userinfo.js it's going to be the same as our previous one with modified a little bit to fit for the future of the boot so what we're gonna do here we're gonna require a couple of objects from the discord.js package so let's open this round or curly brackets and require discord and don't forget your semicolons they're required but most of the time they really are required so let's grab the context menu interaction and the message embed you see here we require the context menu interaction not the command interaction like we use in a different kind of commands all right so we're gonna model dot exports and here the name of the command is gonna be user info and here we can set the type of it to be user because it's um i'm going to show you the different types here we have three different types of application commands a message for example if we go to our discord and we send a message and here we can right click on it and if there is a boat in your discord server that has that app function then you will be able like a rhythm or um i think ruby for example had that option where you can add a song to cue by right clicking on the message and click on on add to queue and the user is the one where you click on the actual uh member and the app will pop up like we saw in the first seconds of the video so in here the type will select user because it's a user command and under here we can use the permissions uh it takes the same permission handling as our normal command so let's set the permissions for example so permission administrator just for example all right and here now we're gonna execute or async execute like we normally do let's remove this line this auto completes for some reason and what we're going to execute is the interaction and we'll open a code block but now here we'll grab our parameters which is command interaction for the interaction all right now to get the actual target member so if i clicked right click on here and got and they wanted to do an application or a command on that user uh and in our normal way of getting the target it should be let's go to our moderation for example it should be going to get the target from an option but here we don't have an option really so here we're going to type const target oh let's do it in lowercase letter equal to a weight here we're gonna wait that's why we used asynchronous we're gonna interaction.guild uh members so we're gonna fetch that member so members.fetch and he will pass in interaction dot target id so what we're getting from this context menu is the target id which we are fetching from the interaction guide it's pretty simple now here we're gonna we're gonna construct our message in bits we're gonna type cones response equal to scroll up equals to new message embed we can set the color to be whatever you want let's set it to be out one now for the author let's set the author it's gonna be the target.user.tag for example and we'll set the small picture next to the author to be the authors or the targets uh profile pictures to target dot user dot icon see here no it's avatar url we set it to be dynamic set to true and the size will be whatever let's set it to be 500 it's required now for for some reason to set that the size of it so either way we're gonna set the thumbnail to be also the profile picture so set thumbnail and here we can just copy this line over here and paste it inside we're gonna go down one more line and here we're gonna add a field and the first field is gonna be target id so id is gonna be the let's see here target.user.id or you can take target.id it doesn't matter it's up to you i like to use the user and get the id from the user updates it's my personal preference and now here we're gonna set it to true to be inline all right so now we're gonna go down and we're gonna add one more field we're gonna add more fields later on but now for the role so we can display the roles of that member we're gonna map them so target dot roles dot cash and here we'll map each role by roll so roll roll and then we're gonna join the roles with a space and then we're gonna replace a role that's called everyone so basically with this code let's go to our discord server uh we'll see this everyone will roll everybody in the server has it but we want to remove it because it's not necessary to replace it because everybody has it so replace we're gonna replace at everyone with an empty space all right it's pretty simple and now uh it's going to give you an error if you replace that everyone will roll and that number that you tried that the command on doesn't have any rules so it's going to send you an error so here we're going to type or none so if we didn't find any rule except that everyone we're gonna basically say none that the user or the member has no rules and by the way we can remove that through from here because we're not gonna be using it with the rest of the fields so we're going to create another field and the name of it's going to be member sense so here we'll set basically whatever whenever the members run the server so it's going to be formatted with the discord is a new formatting or time formatting so this bracket see and then here we place person target joined at time stamp sorry join time step and we're going to divide it with 1000 so the reason we're using sorry let's use the other slash not this one uh so percent is going to basically round the number so we don't get the decimals and we are dividing it because this is this returns a number in milliseconds uh thank you spike mike for annoying me uh all right so we're gonna end this format so uh let's put an r and this bracket and now true um yeah and for the last one let's copy this line over here and change the member sense to be discord user sense and instead of the target.joint timestamp we can type user target.user and here created timestamp and we should be good to go now we're going to go down one more line and type interaction or you can we can return whatever you want you can return if you want to do if you don't want whatever interaction reply [Music] the embeds we cannot pass in the response event and we're going to make the command deferment it's pretty weird to check people's user info you know with them seeing in the moon alright so let's try this out we'll restart our boat note this but alright so we got no errors so let's go to discord now if you right click on somebody's name for example this one we can go to the apps user info and like you see here it will display that user's info in an affirmative message now if i remove the rule that i that gives me the administrative permission and i try to command again you can see that it's faded out and i can't use it because i'm missing that command so let me give myself that rule again and try it out again and like you see we have it here so thank you guys for watching and i hope to see you in the next episode
Info
Channel: Lyxcode
Views: 3,229
Rating: undefined out of 5
Keywords: Discord.js v13, discordjs13, discord bot databse, mongoose database, bot database, free discord bot data base, how to create database, discord.js v13, discord.js database, how to connect database to bot, mongodb, robo3t, discord databsase, userinfo, userinfo command, userinfo command discord.js v13
Id: kyRx1sOevII
Channel Id: undefined
Length: 9min 56sec (596 seconds)
Published: Mon Oct 04 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.