Discord yog qhov kev sib tham nrov uas gamers feem ntau siv thiab nyiam. Discord cov neeg siv tuaj yeem tsim lawv tus kheej Discord channel dawb thiab caw tib neeg koom nrog cov channel. Qee tus neeg siv bots ntawm Discord los ua suab paj nruag, tos txais cov neeg siv tshiab ntawm cov channel, thiab ntau dua. Qhov wikiHow qhia koj li cas los tsim bot rau Discord. Txawm li cas los xij, koj yuav tsum tsawg kawg yog paub me ntsis nrog coding vim tias bots ua haujlwm ntawm JavaScript.
Kauj ruam
Ntu 1 ntawm 6: Npaj Khoos Phis Tawj
Kauj Ruam 1. Rub Node.js los ntawm
Node.js yog JavaScript dawb runtime koj xav tau los tsim bots. Koj tuaj yeem xaiv cov ntawv teeb tsa rau Windows lossis MacOS, ntxiv rau cov version koj xav tau. Rau cov txheej txheem no, nws raug pom zoo tias koj xaiv LTS version.
Kauj ruam 2. Khiav cov ntaub ntawv teeb tsa
Ntawm lub khoos phis tawj Windows, tsuas yog nyem qhov rub tawm cov ntaub ntawv los khiav qhov kev teeb tsa. Ntawm Mac, koj yuav tsum tau rho cov ntaub ntawv thiab nrhiav daim ntawv thov/teeb tsa cov ntawv. Nco ntsoov koj nyeem txhua qhov kev pom zoo ua ntej ua qhov kev teeb tsa.
Kauj Ruam 3. Tsim tus account Discord (yeem)
Yog tias koj tsis muaj tus lej Discord tsis tau, koj tuaj yeem tsim ib qho ntawm
Kauj Ruam 4. Nkag mus rau hauv koj tus account Discord thiab channel
Qhib daim ntawv thov Discord ntawm koj lub khoos phis tawj thiab qhib cov channel koj xav ntxiv bot rau.
Ntu 2 ntawm 6: Tsim Bots ntawm Discord
Kauj Ruam 1. Mus ntsib https://discord.com/developers/applications/me ntawm lub vev xaib
Tej zaum koj twb tuaj yeem nkag mus rau koj tus lej nyiaj los ntawm app, tab sis rov qab nkag rau hauv yog tias tau hais kom sai. Hauv ntu no, koj tsim daim ntawv thov siv bot. Qhov no txhais tau tias koj yuav tsim cov apps thiab bots.
Kauj Ruam 2. Nyem rau xiav Daim Ntawv Thov Tshiab
Nws nyob ntawm sab xis ntawm koj tus browser. Lub qhov rai pop-up rau koj lub npe app yuav tshwm.
Ntaus lub npe ntawm daim ntawv thov thiab nyem "Tsim". Xaiv lub npe piav qhia (piv txwv li "Greeterbot") yog tias koj lub app bot ua haujlwm rau txais tos cov neeg siv. Txawm li cas los xij, lub npe zoo li "Greeterbot" tuaj yeem ua rau yuam kev vim nws yog lub npe nrov. Yog li ntawd, ntxiv cov hlua ntawm cov lej mus rau qhov kawg ntawm lub npe (piv txwv li "Greeterbot38764165441")
Kauj Ruam 3. Nyem Bots ntawm cov ntawv qhia zaub mov sab laug
Cov ntawv qhia zaub mov no tau qhia los ntawm daim duab jigsaw puzzle icon.
Kauj Ruam 4. Nyem Ntxiv Bot
Lub pob no nyob hauv qab "Tsim-A-Bot" nqe lus.
- Nyem “Yog, ua nws! "Nyob rau hauv lub qhov rai pop-up los lees paub qhov kev nqis tes ua.
- Yog tias koj tau txais cov lus yuam kev hais txog lub npe uas nrov dhau, rov qab mus rau nplooj ntawv thov thiab hloov lub npe. Piv txwv li, lub npe “Music Bot” tau suav tias yog neeg nyiam heev. Txawm li cas los xij, koj tuaj yeem ntxiv qee tus lej mus rau qhov kawg ntawm lub npe app.
Kauj Ruam 5. Nyem Nyem rau Reveal Token
Cov ntawv tshaj tawm no nyob hauv cheeb tsam cov ntaub ntawv bot. Thaum cov ntawv raug nyem, koj tuaj yeem pom kab ntawv thiab cov lej.
Nyem "Luam" txhawm rau luam tag nrho cov ntawv. Koj tuaj yeem muab nws tso rau hauv daim ntawv nplaum lossis daim ntawv thov app, tab sis nco ntsoov tias koj tuaj yeem nkag mus rau txoj cai thiab tsis muab rau leej twg. Txhua tus neeg uas muaj tus lej tuaj yeem tswj hwm tus bot. Cov cai yuav ib txwm tshwm rau ntawm nplooj ntawv no thaum koj xav tau
Ntu 3 ntawm 6: Xa Bots rau Discord Server Servers lossis Channels
Kauj Ruam 1. Nyem Cov Lus Qhia Ntxiv
Nws nyob hauv cov ntawv qhia zaub mov ntawm sab laug ntawm qhov screen.
Kauj Ruam 2. Nyem Luam hauv qab ntu "Client ID"
Qhov kev xaiv no nyob nruab nrab ntawm nplooj ntawv web.
Kauj Ruam 3. Muab tshuaj ClientID koj tau theej rau hauv qab URL:
“Https://discord.com/oauth2/authorize?&client_id=CLIENTID&scope=bot&permissions=8”
Piv txwv, yog koj li ClientID yog “000000000000000001”, URL yuav zoo li:
Kauj Ruam 4. Muab tshuaj txhuam URL rau hauv qhov chaw nyob bar ntawm qhov browser
Koj yuav raug coj mus rau nplooj ntawv tshiab uas yuav tso cai rau koj ntxiv bots rau koj li channel.
- Nyem rau ntawm lub npov nco-down kom pom txhua qhov sib xws.
- Nyem "Tso Cai" txhawm rau txuas ntxiv. Koj yuav tau txais cov lus lees paub tias bot tau ntxiv thiab cov tab nquag tuaj yeem raug kaw.
Ntu 4 ntawm 6: Coding Bots
Kauj Ruam 1. Tsim daim nplaub tshev rau cov lej bot ntawm lub desktop
Koj yuav tsim cov ntaub ntawv code uas tom qab yuav raug ntxiv rau hauv daim nplaub tshev.
- Cov cai pom hauv kab lus no yog coj los ntawm
- Koj tuaj yeem tshawb hauv is taws nem rau lwm cov lej lej yog tias koj xav tau, xws li cov lej ua si nkauj tsis tu ncua. Qhov wikiHow siv tus lej piv txwv rau bots uas teb rau cov ntawv lossis cov lus txib uas pib nrog "!"
Kauj Ruam 2. Qhib cov ntawv kho qhov program
Koj tuaj yeem siv qhov kev pab cuam kho kab ntawv qis dua zoo li Notepad rau Windows, lossis TextEdit rau Mac.
Kauj Ruam 3. Ntaus cov cai hauv qab no:
{"Token": "Koj Tus lej Token"}
Kauj Ruam 4. Txuag cov ntawv ua "auth.json"
Nco ntsoov tias cov ntawv tsis tau khaws tseg nrog.txt txuas ntxiv.
Kauj Ruam 5. Tsim daim ntawv tshiab
Koj tuaj yeem tsim ib qho los ntawm nias tus yuam sij Ctrl+N (Windows) lossis Cmd+N (Mac), lossis nyem qhov "Tshiab" xaiv los ntawm "File" tab.
Kauj Ruam 6. Ntaus cov cai hauv qab no:
{"Lub npe": "greeter-bot", "version": "1.0.0", "kev piav qhia": "Kuv Thawj Qhov Kev Tsis Txaus Siab Bot", "lub ntsiab": "bot.js", "tus sau": "Koj lub npe", "Kev vam khom": {}}
Kauj Ruam 7. Txuag cov ntawv ua "package.json"
Nco ntsoov tias cov ntawv tsis tau khaws tseg nrog.txt txuas ntxiv.
Kauj Ruam 8. Tsim ib daim ntawv tshiab
Koj tuaj yeem tsim ib qho los ntawm nias tus yuam sij Ctrl+N (Windows) lossis Cmd+N (Mac), lossis nyem qhov "Tshiab" xaiv los ntawm "File" tab.
Kauj Ruam 9. Ntaus tus lej bot
Piv txwv li, yog tias koj xav tsim tus bot uas teb rau cov lus lossis cov lus txib uas pib nrog lub cim "!", Ntaus cov cai hauv qab no:
var Discord = xav tau ('discord.io'); var logger = xav tau ('winston'); var auth = xav tau ('./ auth.json'); // Kho lub logger teeb tsa logger.remove (logger.transports. Console); logger.add (logger.transports. Console tshiab, {colorize: true}); logger.level = 'debug'; // Initialize Discord Bot var bot = tshiab Discord. Client ({token: auth.token, autorun: tseeb}); bot.on ('npaj', muaj nuj nqi (evt) {logger.info ('Txuas'); logger.info ('Nkag mus rau hauv li:'); logger.info (bot.username + ' - (' + bot.id + ')');}); bot.on ('lus', ua haujlwm (tus neeg siv, tus siv ID, channelID, lus, evt) {// Peb tus bot xav paub yog tias nws yuav ua raws cov lus txib // Nws yuav mloog cov lus uas yuav pib nrog '!' yog (message.substring (0, 1) == '!') {var args = message.substring (1).split (''); var cmd = args [0]; args = args.splice (1); hloov (cmd) {//! ping case 'ping': bot.sendMessage ({to: channelID, message: 'Pong!'}); so; // Just add any case commands if you want to.}}});
Kauj Ruam 10. Txuag cov ntawv ua "bot.js"
Nco ntsoov tias cov ntawv tsis tau khaws tseg nrog.txt txuas ntxiv.
Koj tuaj yeem kaw koj txoj haujlwm kho kab ntawv ntawm qhov no
Ntu 5 ntawm 6: Txhim Kho Kev Txhawb Nqa
Kauj Ruam 1. Qhib Command Prompt window
Ntawm Windows, koj tuaj yeem siv lo lus tseem ceeb "Cmd" hauv Windows tshawb nrhiav hauv "Start" menu. Ntawm Mac, koj tuaj yeem tshawb nrhiav "Command Prompt" los ntawm Tsom teeb.
Kauj Ruam 2. Nkag mus rau bots nplaub tshev ntawm lub desktop
Piv txwv li, koj tuaj yeem ntaus cd / Users / Default Desktop / Desktop / FolderDiscordBotName.
Kauj Ruam 3. Ntaus npm nruab discord.io winston avesave thiab nias Enter
Thaum Node.js raug teeb tsa, kab hais kom ua no yuav rub tawm qhov kev txhawb nqa lossis kev vam khom rau bot rau lub desktop nplaub tshev.
Kauj Ruam 4. Ntaus hauv npm nruab thiab nias Nkag mus.
Txoj cai yuav ua kom ntseeg tau tias tsis muaj lwm cov ntsiab lus lossis cov haujlwm uas koj xav tau los teeb tsa rau bot ua haujlwm.
Tam sim no koj muaj tus lej rau tus bot thiab yuav sim tias tus lej tuaj yeem ua haujlwm hauv txoj kev tom ntej
Ntu 6 ntawm 6: Khiav Bot
Kauj Ruam 1. Ntaus hauv kab bot.js thiab nias Enter hauv Command Prompt window
Yog tias koj tau txais cov lus yuam kev, koj ua qee yam tsis raug nrog tus lej bot.
Kauj Ruam 2. Ntaus “! Intro” rau Discord
Nkag mus rau cov lus txib ntawm cov channel uas muaj bot. Cov qauv piv txwv qhia hauv kab lus no qhia tus bot kom teb rau cov lus txib lossis cov lus tshaj tawm uas pib nrog lub cim "!" nrog lo lus "Pong!". Txhawm rau kuaj yog tias tus bot ua haujlwm, ntaus "! Intro" thiab tos kom teb lossis teb los ntawm tus bot.
Kauj Ruam 3. Txheeb cov cai yog tias koj tsis tau txais lus teb
Yog tias tus bot tsis teb rau "! Intro" cov lus ntawm Discord, rov nyeem qhov wikiHow no thiab xyuas kom tus bot tau teeb tsa kom raug. Ntxiv rau, nco ntsoov:
- Node.js teeb tsa kom raug.
- Bot Token tau muab tso rau hauv qhov ntaub ntawv auth.json.
- Koj nyob ntawm tib channel raws li bot
- Tus bot twb nyob ntawm tus neeg rau zaub mov.
- Cov cai suav nrog hauv auth.json, bot.js, thiab pob.json cov ntaub ntawv raug.
- Koj tau rub tawm txhua qhov kev txhawb nqa lossis kev vam khom rau tus bot kom ua haujlwm siv Command Prompt (tom qab Node.js tau teeb tsa).