How to make Slash Commands for your Discord Bot (Discord.js)
ฝัง
- เผยแพร่เมื่อ 15 ก.ย. 2024
- Learn how to make Slash Commands for your bot in Discord.js!
In this bit, we go through the basics of Slash Commands like registering them, replying and more. I've been trying the "explain more and copy less" strategy so you can actually learn a thing or two while watching the video.
I've been trying so long to finish this video as soon as I can but always winded up in some irritatingly circumstances that would prevent me from working on it.
Watch the Beginner's video: • How to make a Discord ...
If you feel like you're stuck or something isn't working, don't hesitate to join my Discord server. We'd be happy to assist you!
/ discord
Loving my content? want to support?
How about joining my channel membership, you'll receive amazing perks, and I would be able to brew some coffee too.
/ @imaginegamingplay
And I'll be seeing you in the next video. Let's hope it's not another year.
Out of 100 tutorials I watched this is the only one that explains clearly!! You earned yourself a sub man!!
happy 18th bday dude! (i was watching the embed tutorial when you said your bday and i realised im watching on your 18th haha)
Thank you! Atleast someone remembers
Big W! Looking forward for the part 2 and upcoming future videos. Keep it up mate
Bros Comback 👀
Yo, you are back on youtube :D
Haven't seen this name in a while... Welcome back IGP.
The legend finally came back, a big W fr
“Hey, I hope you are doing well. I just wanted to say that over the past few months, our conversations have really meant a lot to me and I’ve developed feelings for you. I enjoy spending time with you and I love how you make me feel when I’m around you. I’m telling you all this because I care about you and I think you deserve to know the truth. So I just want you to know that my feelings for you are real and I want you to think about it as well.”
Thank you for making this video! This was super helpful!
Waiting for next part🎉
For some reason when I execute the code in the shell, some error pops up mentioning "Cannot read properties of undefined (reading 'setToken')" how can I fix this issue
fixed it or still?
Holy shit bro came back
i keep getting to @4:30 where i run the "node name-of-file.js" and it tells me "TypeError: REST is not a constructor" yet this is what my code looks like
const { REST, Routes } = require("discord.js");
//Info needed for slash commands
const botID = "here i have my bot ID, ignore this part";
const serverID = "here i have my server ID, ignore this part";
const botToken = process.env.token;
const rest = new REST().setToken(botToken);
const slashRegister = async () => {
try {
await rest.put(Routes.applicationGuildCommands(botID, serverID), {
body: [
{
name: "ping",
description: "just ping command, lol."
}
]
});
} catch (error) {
console.log(error);
}
};
slashRegister();
thoughts?
Sorry for ignoring, are you using the latest discord.js version? If you don't know how to check, do let me know.
@@ImagineGamingPlay ~/AttachedSwelteringLearning$ node slash-deploy.js
node:internal/modules/cjs/loader:1146
throw err;
^
Error: Cannot find module 'discord.js'
Require stack:
- /home/runner/AttachedSwelteringLearning/slash-deploy.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1143:15)
at Module._load (node:internal/modules/cjs/loader:984:27)
at Module.require (node:internal/modules/cjs/loader:1231:19)
at require (node:internal/modules/helpers:179:18)
at Object. (/home/runner/AttachedSwelteringLearning/slash-deploy.js:1:26)
at Module._compile (node:internal/modules/cjs/loader:1369:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
at Module.load (node:internal/modules/cjs/loader:1206:32)
at Module._load (node:internal/modules/cjs/loader:1022:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/home/runner/AttachedSwelteringLearning/slash-deploy.js' ]
}(
this is the error i get on the same step
im also getting the same problem, have you found a fix?
edit:
i think i fixed it, take off the "()" in
const rest = new REST().setToken(botToken);
so it should be
const rest = new REST.setToken(botToken);
but for some reason it doesnt show it on discord, i even made prefix command and nothing would print
@@artman3 im actually just now seeing his reply.. fuck me. i havent found a fix btw, but as he said to me check to see if you're using the latest discord.js version since that might be the root of our issues
@@ImagineGamingPlay just now seeing your reply 😭 im not 100% sure if i am or not, ill get back to you on whether or not it fixes the issue.
GUYS HES BACK
here u go sir.
I feel bad for you..
fr feel bad that the creator didn't reply or pinged ur message
My bad
Not sure if anyone will see this, but for some reason it keeps saying something alone the lines of REST isn't valid or smthin, I genuinely can't do anything because rest wont work. Any advice?
You need to be a little more specific about the error
@@ImagineGamingPlay REST is not a constructor is what shows up
bro came alive
Thanks, you made it looks easy
My mans backkkkkkk! Les goooo
He is back
I made my own bot! Thank you!
Yooo bro came back
This is a well paced, all rounded video, however I would like to mention that the lack of 4k really ruining the experience for me, nevertheless, I will hesitate from calling this video bad because of the pros I mentioned above. Looking forward to see more videos, but the next time with 4k.
Thank you for your understanding.
omgg bro tyy i need this a lot
Thank you a good video keep up
slayyyy skay 💅
W
ooooraaa
Amazing tutorial
Thank you man
Bro remembered his youtube password
It says my token is not present when I tried to run the command in shell. How do I fix this?
Edit: now it says discordapi error 401 unauthorized
Edit 2: ok it says my token is invalid/unexpected when I type node slash-deploy.js
have you fixed it yet
I'm having the same issue, any help would be appreciated
@terracottasucks it means your token is invalid in the security tab
not sure if anyone will see this, but for some reason my slash command simply just doesn't appear. my bot is online, and it is in my server. but the slash command doesnt show
Have you tried refreshing your client?
can u make a video with a slash command with embed having options?
i didnt hear you get rebooted man
shell says that "TypeError: REST is not a constructor", what do i do to fix?
Sorry for ignoring, are you using the latest discord.js version? If you don't know how to check, do let me know.
@@ImagineGamingPlay how do you?
@Zachary_24 Go to package.json, and there you'll see a line which goes something like "discord.js": version, from there you can see the version. (like 14.x.y is v14)
@@ImagineGamingPlay mine is 1.0.0
@@MrGamerBoyYTOrg you're seeing the wrong line
bro who got his reboot card 💀
Post more i need you
Roger that
Can you make a tutorial of how to make your bot be seen on the bot directory?
Hey can I code a bot with you?
when are you coming back
Very soon
@@ImagineGamingPlay W
could u make a video next on how to make reaction roles?
using ur bot ofc
Who tf revived you
Found my reboot card
@@ImagineGamingPlay nahhhh bro you're literally our careless father in bot development you thaught as the most basic things and went for milk and we learnt everything advanced ourselves. Joining your servers feels like nostalgia. Sending code with token and using that one dog bot (chiku was the name ig) tag system to get code like "start" tag and other tags for commands' code.
Started from copying others code from your server to teaching others bot development. I've come a long way (now it's boring but I wanna restart).
Love from India buddy ❤️
BRO 3:38 TELL ME WHAT TO DO LIKE UR JUST GOIN BAM BAM QUICK apart from that good work sorry
Calm down
@@ImagineGamingPlay i got anger issues sorry
Did someone press your start button?
Yes. I did
Igp revived discord bot help
Eii, so I was wondering. Coul you please remake the first videos? The codes aren't working anymore
I might as well do that
I keep getting an error called "REST is not a constructor at Object" does anyone know how to fix it?
how are you definine "REST"
Hey I don't know what is happening but for require("discord.js") it says "File is a CommonJS module; it may be converted to an ES module." I am really confused
It also says cannot find module
Your initial comment is just a warning. For your second issue, you don't have discord.js installed most likely
@@ImagineGamingPlay thanks but I have it installed
Keeps happening to me aswell, anyone know what to do?
@@MuddyIsCool i some how fixed it
Yo why taking so long for a video create more videos
Can you explain how to code our bots like without checking tutorials os it possible ?
The king is back!
Yes sir!
so for me it says "REST is not a constructor" so maybe i need to update my discord.js version. how do i do that without fucking up the codes?
nvm i've done it but idk if my codes still work like before. It's saying "ReadableStream is not defined"
@@kodzukennnnn Your node.js is outdated. are you using an old repl project perhaps?
@@ImagineGamingPlay nope it’s new and i stopped using replit cause they told me that it’s not that safe so don’t worry! thanks for answering
if you want more info about replit i could dm you on discord
how to fix
error message
ReferenceError: ReadableStream is not defined
at Object. (/home/runner/bot/node_modules/undici/lib/web/fetch/response.js:530:3)
at Module._compile (node:internal/modules/cjs/loader:1198:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)
at Module.load (node:internal/modules/cjs/loader:1076:32)
at Function.Module._load (node:internal/modules/cjs/loader:911:12)
at Module.require (node:internal/modules/cjs/loader:1100:19)
at require (node:internal/modules/cjs/helpers:119:18)
at Object. (/home/runner/bot/node_modules/undici/lib/web/fetch/index.js:11:5)
at Module._compile (node:internal/modules/cjs/loader:1198:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)
my code
const { REST, Routes } = require("discord.js")
//info
const botID = "1270926735382413343"
const serverID = "1270933837068898305"
const botToken = process.env.token
const rest = new REST().setToken(botToken)
const slashRegister = async () => {
try {
await rest.put(Routes.applicationGuildCommands(botID, serverID), {
body: [
{
name: "ping",
description: "Replies with pong!"
}
]
})
} catch (error) {
console.log(error)
}
}
slashRegister();
IT SAYS INSTALL REPLITS NODE TOOLS
BRO WHERE WERE YOU
how to download discord.js v14 on replit. It only shows v14.14.1
that's still v14
❤❤
How to make, that the bot loggs into an Fortnite account?
it says Rest is not a Constructor how the hell do we fix that??
I'd need to see your code for that
@@ImagineGamingPlay So it no longer does that but it wont do a command still after running into no errors.
I cant use spaces or Capitals in my Command name anyone help me?
You cant use them, for example you cant do “/Ping Me” but you can do “/ping-me”
@@stilry I have seen multiple commands use spaces though
@@Kaiser_Playz might be like special coding or something
@@Kaiser_Playz Those are called sub commands
Yowtf
what is the software you use to code?
replit
Hi
PASTE BIN>>>
7:40
not working
Which discord.js should we use?
v14
Bro took a whole lifetime to post
First comment. Likeeee
idk why but this is bugging my code
Fixed?
imagineeee
But
👋👋❤❤
❤❤
I am fast as fk boiis
YOU ALIVENED FROM THE DEAD WTF
speed
firstt
Nvm
Igp, can i please get unbanned on your server? I had been banned a long time ago just because of joking.
z
goofy ah voice
I dont use these AI voices I don't trust them look up No Text to Speach and he will help you his a real person and isn't a AI voice that says get me to this like and I'll do a voice reveal
What?
Can you explain how to fix this?
ExpectedConstraintError > s.string.regex
Invalid string format
Expected: expected /^[\p{Ll}\p{Lm}\p{Lo}\p{N}\p{sc=Devanagari}\p{sc=Thai}_-]+$/u.test(expected) to be true
Received:
| 'ping'
Have you fixed it or still need help?
Yooo bro came back