FiveM Scripting 24 - Discord Bot in FiveM [1] - Show and replace participant count number.emerge as a patreon gentleman today and. receive a ton of perks adding just. college rose early entry content material exclusive. support channels code snippets and extra. become a member of in these days at patreon.com jjs alright. what's it bet my name is Xue er from. Java at present we are gonna be creating a. discord no longer that runs with FX server so. yeah that is literally what we're gonna. do today the code that we're gonna write. is in the description under this link. you could entry it there I will placed it down. there and all any other links that we're. gonna need I will put these too. so let's in fact start let's open. up a server let's open our server folder. go to assets i'll create a. new folder and the source referred to as. discord bot and in here i will. open this and vs i am gonna create a file. here known as so recently or i think like.four months ago they changed or I. haven't performed this afterward. but they changed 5 em transformed the way. that you write your source Louis so. rather than underscore underscore. source that Lua they changed it to FX. take place happen there we move dot Lua. similar to that aand then in here we have. to do some new things so we're gonna. have got to claim the FX version because the . VOD ACA us bodacious i feel after which. the games that it runs on its gta5. and then we also want to do our server. underscore script so the carrier script. we're gonna be writing out the server. script is gonna be bot J s a twin of. that and now let's correctly make our bot. Jess right here clone of that we're not gonna. do whatever right here cuz we have to in. initiate and p.m. so through how you. should have node mounted nodejs. mooji's org make sure it really is hooked up.on your computing device I will put this link in. the description once that's installed it. additionally installs NPM which is the node. package manager so open up your command. prompt I will do exactly it like this. let's open up command prompt and then we. must CD. click right here replica this and click on CD. and then right click enter your in that. director just CD into this listing and. what we want to do is do NPM in it and. then the package call we are just gonna. name it discord bot the edition 1 i am. nice you may just click enter for all. those it genuinely does not matter. ensure the access factor is the same. name as this bot Jess your identical call as. your JS dossier so i am gonna click on input. experiment command would not matter just doesn't. matter that this doesn't topic this. would not subject now that really matters. but we've this kit Jason now.What we want to do is we have to set up. this Fork of discord GS due to ice. axe here he made a version of this. fabulous that truly works with 5m. natively the original version of this. chord is like the conventional library that. does not work with FX server as a result of. issues I guess yet he made a fork. that really does make it paintings on 5m so. we are gonna be installation his fork. in preference to the conventional discord jeaious. things so to do this we're gonna do. here I'm gonna do NPM set up NPM. install i am simply gonna copy his name I. don't desire to variety that out. oh i am gonna try this I will simply do this. NPM superstar shrink discord is rather like that. you want to enter this command here and. I'm click input. ok so as soon as that is hooked up and yeah. once that's set up you ought to see a. new folder pop up referred to as node modules.and that is skill it labored I guess it. must have discord adieus in there. so yeah we just about just did that we. mounted discord ah yes so now what we. want to do is open up the bot j/s and. now what we wish to do is actually we are. gonna be writing the code for so for the. bot we need to commence with getting. them so if you're not used to no js' i am. sorry I'm gonna attempt my finest to describe. how it really works so we are gonna have a. constant and it's gonna require the. module that we just installed so it's. when you require simply scourge a s simply. like that aand then in here we're gonna. want to take just aa client object from. right here after which um. we have the desire to make a console purchaser with a. lowercase C no longer i'm not an uppercase C. yet we're gonna do new customers so we. correctly use this variable from right. here do not don't forget approximately this bit.Like we are gonna be using this purchaser. you're not chuckles pleasant and right here. a dead ringer for that and now what we wanted to. is we are gonna do worldwide config is equal. to require dot lower config dot JSON so. what it's we are gonna we have the desire to make. a config JSON dossier so i'm gonna click on. new dossier a brand new convict that's a Sun and. then in right here we are gonna have an object. and the bottom line is gonna be token after which. the cost will be blank for now we need. to truly so the whole factor of this. is simply to put it placed our lot token in a. specific file simply so like it is not in. the main aspect right here this file we are. gonna be used to. positioned our Bach token if you want to log into. the bot and really use it we're gonna. let's make that truly later I desire to. write all this primary so i have to so to. actually begin the bot or when it.In fact starts with your purchaser dot on. and then on all set the prepared occasion we. want to have a function here it is with a. new slender operate we'd like this. operate to console.log with these these. specific characters right here it is on. the tilde key here and then we. want to save this chord. we are just logging thiis just simply you. can see that the bot logs in so discord. logged simply what approximately logged in as. purchaser consumer tag and then yeah which means. it's logged in and then we wanted to. in fact now log in to it so to try this. we do purchaser login and we're gonna do. config dot token like so after we take. this config variable. it will take its token estate and we. want to really set that so let's do. that at the moment correct you are gonna need. this hyperlink here I will positioned this in. the description lower than make sure you're.Logged in to discord so I'm logged in in. my main account that is um it is satisfactory. and now we wish to do if it's your first. time you are probably not gonna have any. purposes that's nice i think I have. performed this earlier than but we're simply gonna. click new software i am gonna type in. Java that is what I desire to call the bot. make sure cuz you can't difference this I. understand you can also make a brand new one but just. make sure you name it you want. so I called mine Java i am gonna placed an. icon which I myself do have here units. I'm simply sort of gonna have to do this. laptop emblem there we cross and then that's. set because the Java logo and now what i want. to do is click on this field area then. I desire to click on at bot then do definite so. then here we actually spawned in. the bot and we now not spawn didn't yet we. made the bot so now what we want to do.Is reproduction our token here it truly is. what we want don't give this to anybody. incidentally i am going to regenerate this after. but yeah. so paste that during directly like how you. copied it and let's shop that now we. prefer to return into our physique is and now. what we want to do is let's make it loop. we are gonna make it constantly loop the. player count number of the server or whoever's. in the server so to do that we're gonna. make it folder and we're gonna call it. utils there is only gonna be one application. and i am during this folder I'm gonna do. index J s a twin of that if you do not if. you can not genuinely visualize the structure. it truly is it utils and index J s after which. during this index step in XS J's dossier we. desire to do module exports is the same as. object after which the only object in right here. we are gonna have it is gonna be a. operate it is gonna be update replace. https://wefx.info/discord-bot-chat/ and then we want to do client , seconds. so this operate we're having it is gonna. have two parameters which is the customer. object that we are gonna go through so. we can actually set the bots fame if. you're not familiar with the discord. digest API I will hyperlink that lower than there is. terrific they've useful. documentation for that aand then seconds. we're gonna use this to put what number. seconds you desire for it to replace so. like that refresh expense i assume so in. here let's make a variable known as Const. interval interval after which it is equivalent to. a operate that is set period and. then this operate inside this is. gonna have one other function known as set. repute identical to this it is confusing. sorry after which inside the correct after. the set status function we want to put a. comma or no we need to placed one more.Parenthesis and a comma and then we'd like. to do seconds time instances one thousand because. set period makes use of milliseconds so this. is just gonna convert it there's a. thousand seconds by what percentage seconds you. prefer so it'll simply multiply that'll. go back how a lot what percentage seconds you. want to loop it every time so in right here we. desire to do reputation it's aactually yeah I'm. gonna do let's reputation is persons or. correctly don't want to make it do it. whenever I'm simply gonna try this. yet status equivalent to i didn't correctly do. this in the code right here we're simply gonna. allow fame correctly no i do know I not ever. intellect just forget me so i am gonna do allow. fame fame is the same as these same. keys back tilde it's at the tilde yet. right here this and then we wish to use. a native movement so we're gonna do get. numb player in dices so this would this.This local here it is a 5 . emanated this isn't a discord chess. native and all it is immediately from 5m. server which is truly it's is magnificent. that you'll be able to use that just you can use a. bunch of server natives now due to the fact. you are using the Jas edition of this. gorgeous edition on FX server so that's. amazing so you do not even have to like. request it from a backend server you. can actually just run it and use the FX. server natives which is awesome so we. desire to do get range players we want. gamers and then we want to have it like. that so it'll be like that is the popularity. of your bot after which it will appear as if. like if you had like 20 persons on that is. what the screen looked like will be. like 20 gamers that is what that is what. that want return if there were 20. persons on and now what we want to do is.Do purchaser it truly is what we are utilizing the. client object right here that we're gonna pass. it will definitely purchaser dot user dot set. undertaking set endeavor the image of that. after which we wish to set it as that. string that we set and then you are able to do. we need to placed an item right here and do. sort and then I need to make it look. like it's watching 20 gamers rather than. like gambling like as like a normal. status that could be like looking. instead and there's like two others or. you can also make it seem like it is streaming. or it's looking or listening or playing. as a way to simply make it look like. it's. just eliminate that yet I want to make. sure it appears like that aand then we want. to come set status because we need it. to begin in the beginning of the. interval so it does not have to wait so. that is that's just about it for this.This file now we want to call it into. right here so what I want to do correctly is to. name this dossier so to do that we are just. going to be fixed update or require. so we'll require the hot util. this component so dot lessen info and an. index you don't have to place that during. there because it's the index similar to. that aand then we are gonna do update. participant account like that correct there and. then now we can actually use this. operate in here oops I want to replica . that i am gonna use this operate update. participant account after which we wish to do. client we wish to move the customer item. in and then we additionally prefer it to do it i am. gonna do it every five seconds be sure. you do it if you're gonna change the. seconds you I intend to make it refresh. the participant counter or update every 5 . seconds yet do not do it we don't do it.<iframe src="https://www.youtube.com/embed/vxJ5Sbe0pio" width="560" height="315" frameborder="0" allowfullscreen></iframe>greater than requests every second. due to the fact that is abusing that is. interestingly abusing the discord API so. make sure you're doing if you're doing. greater than like requests a second. that is undesirable do not do that i'm just gonna. do it each five seconds it'll do one. request to the discord API which is great. so yeah that's pretty much it for this. here I'm gonna run thiis now so i've. the bot token i personally I forgot to now. what we want to do correctly I forgot to. we have to truly invite the bots so. i am in my discourse server here and to. in fact invite your body you would like this. link here i'll positioned this is sort of a. template link here i am going to put this. link so what we need actually is good. right here so it says your purchaser identification when it. says purchaser identification is equal to your purchaser. Identity i am gonna backspace that. to Chrome here for a second there is.Chrome there it's yeah and i'm gonna cross. back to my trendy information there. where it says client Identity I'm going to. reproduction that aand I'm gonna paste that where. it says client Identity is equal to that magnitude. after which make sure it is right here scope is. equivalent to BA and then permissions is. equivalent to 8 this just about signifies that. the bot is gonna have an inherited admin. function on your server. there's actually a permissions. calculator i am going to put them within the . description if you want it to like no longer. have admin or simply in basic terms if you wish it. to only to ship messages it would not. topic I will positioned that during there in case you. desire to set this number as anything. else and make it not have admin yet I. don't really care so i am gonna once I. even have that setup I'm gonna open. it yeah now it says connected Sheva to. discord the item so I'm gonna visit it.Sue a server a hive to sua servers there. we pass i'll click connect. optimistically that's the right one it's the. right one I do not know why i need to do. a servers but there we move says Java is. joining the provider so it's aactually. offline now to make it on-line what we. want to do is i get out of here at 11:00. I'm gonna start the server. and then it says began resourced it's. referred to as began source disgorge yet and. then it says discord bot logged in as. java hash six 8 to seven then it. says it is called neo Java to stick I. can't even see the object but you'll discover. that it's on-line now and it says it is. looking zero gamers i am gonna go into. the server and I'll show you that it'll. say one players once I'm in there ok. so i am in 5m now sorry about my machine. yet i am gonna connect with my server here.after which it is gonna discord it's going to. already say that i am at one players. there it goes it changed and it's gonna. assess that each five seconds that's. high-quality that's like ideal and that's. almost it for this video thanks . guys for looking if I give up you will discover. that it is gonna leap right down to zero. gamers it is relatively quick approximately it which. is amazing i'm hoping you guys enjoy the. video I'm correctly gonna make extra of. those videos with this score digest with. this Fork because there's a lot you may. do with this and yeah that is yeah make. sure to LIKE and allow me recognize if you wish. more of those movies too because there. you may have instructions and make it. work together with your server it is like. there's such a lot of possibilities so i hope. you men benefit from the video and yeah see. you guys later. also I forgot to say that after the.


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2022-01-19 (水) 01:28:22 (828d)