hey i need help. at 5:49, when i try and run the node src/register-commands.js it comes up with registering slash commands... There was an error: DiscordAPIError[0]: 405: Method Not Allowed i followed you exactly but it isnt working and i cant find what the issue is.
Hey Under Ctrl. The odds of you seeing this are pretty low, but I want to say these videos have been helping immensely. Don’t ever stop what you do, man.
By far the most useful video I could find about slash commands, extra props for actually writing the code live and not just dumping a bunch of pre-written code. Thank you for the very clear video :)
If your code for around 5:34 is not running (like it's not printing anything, just ignoring), make sure you add a (); at the end in order to invoke the function. Problem (console): Node.js v18.15.0 PS C:\Users\W\EconomyBot> node src/register-commands.js PS C:\Users\W\EconomyBot> Example: (async () => { try { console.log("Registering slash commands..."); await rest.put( Routes.applicationGuildCommands( process.env.CLIENT_ID, process.env.GUILD_ID ), { body: commands } ); console.log("Slash commands registered."); } catch (error) { console.log(`Error: ${error}`); } })(); The (); at the last line invokes the entire function and makes it run.
yeah it uses an immediately invoked function expression if u didnt want, u can identify it and then call it like this (remove brackets around async) async function registerSlashCommands() {..rest of code} then use registerSlashCommands()
Thank you for creating this video! I was looking for the way to add slash Commands, but other guides didn't help. After watching this video all works successfully.
just got into nodejs heavily recently, thanks for showing how to set up nodemon -g it saves so much development time i believe instead of having to go back after every change to manually rerun code🤘
Hello there! I am thoroughly enjoying the content that you produce. Your videos are of high quality and I have just subscribed to your channel. I kindly request that you consider making some videos on how to customize an OpenAI bot. Thank you!
Amazing videos. Even after following the tutorial I’m still messing up, resulting in me researching and looking for my mistake which I think is a great way to learn although frustrating.
i did everything correctly and rewatched this multiple times, but the commands dont work there are no errors, but when i use the slash command in the server, it says "the application did not respond"
For those of you getting "TypeError: (intermediate value).setToken(...) is not a function".......................put a SEMICOLON after "const rest = new REST({ version: '10' }).setToken(process.env.TOKEN)"
@underctrl Its saying "there was an error: discordapierror [50035]: invalid form body name [application_command_invalid_name] command name is invalid... how to fix?
I was getting error: Error at: DiscordAPIError[50035]: Invalid Form Body 0.name[STRING_TYPE_REGEX]: String value did not match validation regex. Resolved by deleting {version: '10'} in line 11
Amazing video, although i have one problem. The code is exactly the same however an error pops up when executing node src/register-commands.js, It tells me: There was an error: DiscordAPIError[50041]: Invalid API version. Any way how to fix this?
For anyone who possible gets this error CODE: "DiscordAPIError[50035]: Invalid Form Body 0.name[APPLICATION_COMMAND_INVALID_NAME]: Command name is invalid" your command names have to be all lowercase. literally spent 45 minutes trying to figure this out. Hope it saves someone some time
As the Discord.js documentation says: "it's not a very good idea to have a single file with a giant if/else if chain for commands. If you want to implement features into your bot and make your development process a lot less painful, you'll want to implement a command handler." This way works, but is not the best one.
Great Video! But I have a question. I tried adding a new slash commands, but it doesn't seem like the code even recognizes that it's there. I've refreshed many times, but it still won't work. Is there a way you could help?
Hey. There’s a few reasons on why you might be getting that issue. My doubt is it’s probably your commands structure. Join my server discord.gg/T4faJeH84A and I’ll help you troubleshoot the problem.
gives me this error: DiscordAPIError[20012]: You are not authorized to perform this action on this application every time i try the node src/register-command.js command
When i attempt to turn on the bot after writing the register-commands file, the bot straight up ignores it. No console.log events appear, no texts, no warnings. It just tells me that the bot is online. What did I do wrong? Edit: nevermind, i figured it out. I just had to run node src/register-commands.js first before turning on the bot. After doing that, the commands appear and work.
You can do that as well, but I thought of having a separation between the two so I may explain things a little better. I cover command registration on startup later in the series using a command handler.
@@UnderCtrl Thanks! I was reading in the discord.js guide that it’s a good idea to put it in a separate file because Discord limits the number of times you can register commands daily. Now I’m trying to use SlashCommandBuilder() to create commands with options and permissions, but it’s giving me a body formatting error when registering the commands. I also read in the guide that you need to create a file for each command and do several other things... I think It's absurd for something that should be simple. I just watched your handler video... man, first of all, thank you for making these videos, and I think your method of doing things has a basis, but it adds too much complexity for something that is a simple registration and functionality of commands. I don't see the point in adding multiple files and folders. Bro, I have a bot made in Java (JDA) where the commands are registered with all options completed in literally 2 lines of code, and an event listener directs the actions to a command manager class. It's that simple. There must be a way to do this in a simpler way with JS.
Noticing that your codeblock has far fewer whitespaces than mine.... I've been using TAB for indentation but is there a more formal way of doing this or should I continue with what I'm doing?
i keep getting There was and error: ReferenceError: Routes is not defined does anyone know how to fix? i trid to fix it but made it worse now its saying Expected token to be set for this request, but none was present
Whenever i try to do this it says my console log for the error then "DiscordAPIError [50035]: invalid body name[STRING_TYPE_REGEX]: String value did not match validation regex. How do i fix this? figured it out, i just had to take away the ! point... took me 3 hours to figure that out.
Hello, I was wondering if there was a way to have the GUILD_ID be set so that the bot can be accessible on any other server besides the test one you made, and I wasn't sure if this would be in a future video, so I am asking here now. I can be really bad at explaining things at times, so I hope you understand what I meant. Haha 😅
Hello Under Ctrl, i habe an strange issue. I build a discord app and i gave im the right rights as yours in the video. Then i build the bot and run him as a docker container. Now the strange starts. If i run him on my local maschine in docker compose the / commands working fine, but if i run him on my raspi the app crashes and say "discordjs can't regonize the command" . Its the same for a simple / gives text command and a / makes a database and fetch data command. Do you have some guesses why? I work with await interaction.deferReply({ ephemeral: true }); and interaction.editReply({ content: "some content", }); and with interaction.reply({ content: 'some content', ephemeral: true, }); nothing work on raspi. And Yes the commands are registert
hey ! i really apriciate that you making these type of videos there are awesome tutorials! but i have a question can u explain why we need to add AppID token amd guildID to applicationguildcommand? at least i can undertand why for REST you need token that i don't get it why you need App ID and Guild ID , like we already creating bot and there no need of AppID . Also its a nice feature that you can test some command before lunch to global but why i how to change guildID that could works on every server?
in your src/register-commands.js replace this await rest.put( Routes.applicationGuildCommands( process.env.CLIENT_ID, process.env.GUILD_ID) { body: commands } ); put this instead await rest.put( Routes.applicationCommands(process.env.CLIENT_ID), { body: commands } ); it should be fixed
For anyone having the error: 0.name[APPLICATION_COMMAND_INVALID_NAME]: Command name is invalid. make the name between the strings LOWERCASE! name: 'Hey' is NOT gonna work. Instead, try name: 'hey'
There was an error: DiscordAPIError[50035]: Invalid Form Body 0.name[APPLICATION_COMMAND_INVALID_NAME]: Command name is invalid. I have that error pls help me
Nice video, but i have problem DiscordAPIError[50035]: Invalid Form Body name[APPLICATION_COMMAND_INVALID_NAME]: Command name is invalid. Can you help me solve this?
One of the commands you’re registering has an invalid name. Make sure it doesn’t have any space, only letters and make sure it’s all in lowercase. If all your command names are fine then check your options inside your commands to follow the same pattern. Options can however use “-“ in their names.
Hello! Thank you so much for these tutorials. Something I noticed is that every time I add commands to my bot, I have to kick and reinvite it for the new commands to show up. Is there a way to have them automatically appear without a kick/rejoin?
Hey. So that's most likely a Discord caching issue with the desktop app. Instead of kicking the bot and re-inviting it, I suggest just refreshing your Discord using Ctrl + R (Cmd + R on mac) and you'll get updated commands.
hey bro ! fantastic vid, it really elps me out as im trying to learn coding, but i have a question, when i write the description: '....' it shows a problem and i cant figure it out, could u please help me?
when I run the command node src/register-commands.js it doesn't do anything. No errors, no / commands on my server. nothing. Just keeps running like nothing happened.
hey so when i try to run the commands or check on it like node register-commands.js it does not work and the was same before when I have try to run the bot same does not work until i use client.login(''); and I closed the .env (deleted) when I open a .env channel and use TOKEN = .... that doesn't work I hope you understand what I'm trying to explain
broo i prmblmm my slash code is registering but after that insted of registerd successfully There was an error: Error: Expected token to be set for this request, but none was present this is showing wt is prob
Can the index js send a slash command, even if there was no interaction initiated on the server? And will the Discord server run the slash command sent? I run windows, so my intent is to set up a daily schedule in the windows scheduler, that would run the js file at a given time everyday
If you want to send some message some time of the day, you can instead fetch the channel and send a regular message. You don't have to use slash command interactions for that. Interactions are only triggered when a user interacts in some way with your Discord bot.
@@UnderCtrl Can the js fetch the channel and send a slash command? I have a particular slash command on a private channel that performs a function. Right now I end up doing that manually on the channel each day, but I want the js to do it for me instead.
@@jryer1 Yes, you can. If you want to find the channel by its id (get the id by right-clicking it in developer mode), then put this code (recommended if your bot is in multiple servers): channel = client.channels.cache.find(ch => ch.id === 'your-channel-id') If you instead want to find the channel by its name, enter this code (recommended if your bot is for one server): channel = client.channels.cache.find(ch => ch.name === 'your-channel-name') After this, you have to send the message using channel.send('This message was sent to its designated channel.') Here's how I would write your full code: // first, run npm install cron in your terminal // at the top of your file const cron = require('cron') // this next piece of code goes inside whatever client ready event you have, whether it is client.once(Events.ClientReady,...), client.once('ready',...), etc.) client.once('ready', (c) => { console.log(`${c.user.tag} is online`) // you may have something like this in your client ready event let scheduledMessage = new cron.CronJob('00 30 12 * * *', () => { // The format is seconds minutes hours, so 00 30 12 would send a message at 12:30 (please note this adjusts for your timezone) const channel = client.channels.cache.find(ch => ch.id === 'your-channel-id') // or channel = client.channels.cache.find(ch => ch.name === 'your-channel-name') // in the above line, if. you define your client as Discord.Client at the top of your code, replace "client" with Discord.Client channel.send('This message was sent at 12:30!'); });
scheduledMessage.start() }); And that should be all! If you have any follow-up questions, please reply to this comment. Sorry for the long reply, but hope this helped!
i tried everything but i couldnt get the src/register-command.js to respond i have the exactly same code as you and it doesnt respond. i need a bit help
I get the following error: An error has occured: DiscordAPIError[50035]: Invalid Form Body application_id[NUMBER_TYPE_COERCE]: Value "undefined" is not snowflake. Does anyone know how to fix this?
After Troubleshooting for a moment, My issue was the env file was not saved. Make sure you save the env file so that the functions are actually retrievable.
I made this mistake too. You need to right click the discord server name. not left click. It looks like Two seperate menus but they look increadibly similar
Thanks for the last video was really helpful! and this is by far the best video yet on how to make discord bots! so right now im coming across this error when i type in "node src/register-commands.js" Registering Slash Commands... There was an Error: DiscordAPIError[50035]: Invalid Form Body name[APPLICATION_COMMAND_INVALID_NAME]: Command name is invalid What should I do to fix it? (I tried looking it up i wasn't able to find my answer so I thought maybe you would know.
The src folder is what we created in the first video. It's not important if you already have an existing project. You can just create all your files and folders in your current directory. If you do choose a src folder make sure to change "main" in package.json to "src/index.js"
Everything is going well, but i am experiencing a problem (async() => { ^ TypeError: (intermediate value).setToken(...) is not a function at Object. (C:\Users\294ad\Captain's Utilities\src egister-commands.js:13:1) at Module._compile (node:internal/modules/cjs/loader:1105:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) at node:internal/main/run_main_module:17:47
I experienced the similar problem, but I figured out how to fix it: const rest = new REST({ version : '10'}).setToken(process.env.TOKEN); You must have corrected it or something by now.
spent 30 min on this error, the semi colon is required when defining rest. this works: const rest = new REST({ version: '10' }).setToken(process.env.TOKEN); this doesnt: const rest = new REST({ version: '10' }).setToken(process.env.TOKEN)
Source code: github.com/notunderctrl/discordjs-v14-series
Discord server: discord.gg/T4faJeH84A
hey i need help. at 5:49, when i try and run the node src/register-commands.js it comes up with
registering slash commands...
There was an error: DiscordAPIError[0]: 405: Method Not Allowed
i followed you exactly but it isnt working and i cant find what the issue is.
@@Leafstuff replace the applicationGuildCommand to applicationGuildCommands (yes you only need to put "s")
@@Leafstuff.
Hey Under Ctrl. The odds of you seeing this are pretty low, but I want to say these videos have been helping immensely. Don’t ever stop what you do, man.
Thanks! 🙏
By far the most useful video I could find about slash commands, extra props for actually writing the code live and not just dumping a bunch of pre-written code. Thank you for the very clear video :)
I love that you show how we can figure things out for ourselves like using console logs and documentations to find parameters
Very underappreciated tutorial. Good job man and your voice is perfect for this kind of videos.
Much appreciated!
If your code for around 5:34 is not running (like it's not printing anything, just ignoring), make sure you add a (); at the end in order to invoke the function.
Problem (console):
Node.js v18.15.0
PS C:\Users\W\EconomyBot> node src/register-commands.js
PS C:\Users\W\EconomyBot>
Example:
(async () => {
try {
console.log("Registering slash commands...");
await rest.put(
Routes.applicationGuildCommands(
process.env.CLIENT_ID,
process.env.GUILD_ID
),
{ body: commands }
);
console.log("Slash commands registered.");
} catch (error) {
console.log(`Error: ${error}`);
}
})();
The (); at the last line invokes the entire function and makes it run.
thank you you beautiful man
Thank you so much internet stranger, may all the blessings be with you
Thank you! This helped!
yeah it uses an immediately invoked function expression
if u didnt want, u can identify it and then call it
like this
(remove brackets around async) async function registerSlashCommands() {..rest of code}
then use registerSlashCommands()
thanks for writing this comment, was stugling on this, but luckily loooked in the commend section
Thank you for creating this video! I was looking for the way to add slash Commands, but other guides didn't help. After watching this video all works successfully.
Glad it helped!
Thank you so much for your videos, I'm learning both English and Discordjs
just got into nodejs heavily recently, thanks for showing how to set up nodemon -g it saves so much development time i believe instead of having to go back after every change to manually rerun code🤘
I'm a viewer from Thailand. Your video clips teach, understand, easy to practice. Keep making good video clips. 😀
Hello there! I am thoroughly enjoying the content that you produce. Your videos are of high quality and I have just subscribed to your channel. I kindly request that you consider making some videos on how to customize an OpenAI bot. Thank you!
Amazing videos. Even after following the tutorial I’m still messing up, resulting in me researching and looking for my mistake which I think is a great way to learn although frustrating.
You videos is so much better then discords tutorials.. Keep it comming
In case you get the following error "DiscordAPIError[50001]: Missing Access", in the GUID_ID put the server id
THANK YOU!!
you are explaining very good!
i did everything correctly and rewatched this multiple times, but the commands dont work
there are no errors, but when i use the slash command in the server, it says "the application did not respond"
idrk the ans but there are some helpful ppl in the server of under ctrl so maybe join that ig
same here..There is no error in the snippet..still in discord. the slash is not registering. DId you overcome the issue?
Thank you!
You forgot to add this thing 'npm i dotenv' , but overall 10/10
This video is part of a series, and dotenv was covered in the video before this (part 1)
For those of you getting "TypeError: (intermediate value).setToken(...) is not a function".......................put a SEMICOLON after "const rest = new REST({ version: '10' }).setToken(process.env.TOKEN)"
I tried this but still keep getting an error
My saviour!
Thank you very much, it helped me a lot.
@underctrl Its saying "there was an error: discordapierror [50035]: invalid form body name [application_command_invalid_name] command name is invalid... how to fix?
Same here, do you happen to fix it already by any chance?
this is awesome ! thanks
A little late for this, but what if I want it to be multi-server?
@underctrl I get an error that says: There was an Error: DiscordAPIError[0]: 405: Method Not Allowed. Can someone help me?
To resolve this error, you can try using a different username that does not contain "discord".
@@SKoRSAwhat do you mean by username, it's giving me this error now too?
The require name?
applicationGuildCommands not applicationGuildCommand
Thank you! you recieved a subscriber
I was getting error:
Error at: DiscordAPIError[50035]: Invalid Form Body
0.name[STRING_TYPE_REGEX]: String value did not match validation regex.
Resolved by deleting {version: '10'} in line 11
Amazing video, although i have one problem. The code is exactly the same however an error pops up when executing node src/register-commands.js, It tells me: There was an error: DiscordAPIError[50041]: Invalid API version. Any way how to fix this?
For anyone who possible gets this error CODE: "DiscordAPIError[50035]: Invalid Form Body
0.name[APPLICATION_COMMAND_INVALID_NAME]: Command name is invalid"
your command names have to be all lowercase. literally spent 45 minutes trying to figure this out. Hope it saves someone some time
OH MY GOD THANK YOU SOOOO MUCH
thx that saved alot of time
THANK U
I’m getting this issue at the moment. Tried it lower case and still the same.
How can we delete the registered commands?
I made some commands for test and now I cannot remove them from the discord command menu,
Please help.
same help
As the Discord.js documentation says: "it's not a very good idea to have a single file with a giant if/else if chain for commands. If you want to implement features into your bot and make your development process a lot less painful, you'll want to implement a command handler."
This way works, but is not the best one.
Agreed! This is just an approach for beginners. In later videos I have covered multiple command handlers that handle registration.
Great Video! But I have a question. I tried adding a new slash commands, but it doesn't seem like the code even recognizes that it's there. I've refreshed many times, but it still won't work. Is there a way you could help?
Hey. There’s a few reasons on why you might be getting that issue. My doubt is it’s probably your commands structure. Join my server discord.gg/T4faJeH84A and I’ll help you troubleshoot the problem.
When I try to run the register-commands.js file it says "DiscordAPIError[0]: 405: Method Not Allowed"
How do i fix this?
Same here
applicationGuildCommands not applicationGuildCommand
gives me this error: DiscordAPIError[20012]: You are not authorized to perform this action on this application every time i try the node src/register-command.js command
When i attempt to turn on the bot after writing the register-commands file, the bot straight up ignores it. No console.log events appear, no texts, no warnings. It just tells me that the bot is online. What did I do wrong?
Edit: nevermind, i figured it out. I just had to run node src/register-commands.js first before turning on the bot. After doing that, the commands appear and work.
i have an error when running node src/register-commands.js . it says discord API Error[1002] . Help?
Hey I'm getting: TypeError: (intermediate value).setToken(...) is not a function. What does this mean? It doesn't let me run any slash commands:(
replace the similar code with this
const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);
@@immuchh I tried this yet still keep getting the same error any tips?
@@hredd9299 ^
Prob very late, but add a semicolon at the end of the line of code (with the .setToken part).
Why not place the command registration in the main bot file, so that the commands are registered as soon as it starts?
You can do that as well, but I thought of having a separation between the two so I may explain things a little better. I cover command registration on startup later in the series using a command handler.
@@UnderCtrl Thanks! I was reading in the discord.js guide that it’s a good idea to put it in a separate file because Discord limits the number of times you can register commands daily. Now I’m trying to use SlashCommandBuilder() to create commands with options and permissions, but it’s giving me a body formatting error when registering the commands. I also read in the guide that you need to create a file for each command and do several other things... I think It's absurd for something that should be simple.
I just watched your handler video... man, first of all, thank you for making these videos, and I think your method of doing things has a basis, but it adds too much complexity for something that is a simple registration and functionality of commands. I don't see the point in adding multiple files and folders. Bro, I have a bot made in Java (JDA) where the commands are registered with all options completed in literally 2 lines of code, and an event listener directs the actions to a command manager class. It's that simple. There must be a way to do this in a simpler way with JS.
Noticing that your codeblock has far fewer whitespaces than mine.... I've been using TAB for indentation but is there a more formal way of doing this or should I continue with what I'm doing?
Yes, in your visual studio code settings you can change the “Tab size” to 2 which is what I use. Your seems to be 4
@@UnderCtrl Thank you! Keep up the amazing work man, been enjoying learning about discord.js.
i keep getting There was and error: ReferenceError: Routes is not defined does anyone know how to fix? i trid to fix it but made it worse now its saying Expected token to be set for this request, but none was present
@Under Ctrl At 5:03 what did you click to put GUILD_ID down? Pleae help.
enter
The slash commands aren't in my server idk why
The env stuff does'nt work for me. It only says that the Token is invalid, i've resetted it and added it to the file, but it still doesn't work.
Make sure .env is in the root level, not inside the src folder.
@@UnderCtrl it is in the root level
@@UnderCtrl lmao been stumped on this ty
how i make the slash commands appear in every server it is?
Whenever i try to do this it says my console log for the error then "DiscordAPIError [50035]: invalid body name[STRING_TYPE_REGEX]: String value did not match validation regex.
How do i fix this?
figured it out, i just had to take away the ! point... took me 3 hours to figure that out.
May i know where you change it? cause I've been struggling with same problem and I don't know where to fix this
Wish you could slow down more and explain more of whats going on
Hello, I was wondering if there was a way to have the GUILD_ID be set so that the bot can be accessible on any other server besides the test one you made, and I wasn't sure if this would be in a future video, so I am asking here now. I can be really bad at explaining things at times, so I hope you understand what I meant. Haha 😅
@@skid-rv8tz No sadly
It's pretty simple, in register-commands.js replace
await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);
and instead put
await rest.put(
Routes.applicationCommands(clientId),
{ body: commands },
);
Hello Under Ctrl, i habe an strange issue. I build a discord app and i gave im the right rights as yours in the video. Then i build the bot and run him as a docker container. Now the strange starts. If i run him on my local maschine in docker compose the / commands working fine, but if i run him on my raspi the app crashes and say "discordjs can't regonize the command" . Its the same for a simple / gives text command and a / makes a database and fetch data command. Do you have some guesses why? I work with await interaction.deferReply({ ephemeral: true }); and interaction.editReply({
content: "some content",
}); and with interaction.reply({
content: 'some content',
ephemeral: true,
}); nothing work on raspi. And Yes the commands are registert
for me everything work, but when i try to make a second command, it's doesn't work :/ 9:24
same, the application doesn't respond and throws an unknown interaction error
hey ! i really apriciate that you making these type of videos there are awesome tutorials! but i have a question can u explain why we need to add AppID token amd guildID to applicationguildcommand? at least i can undertand why for REST you need token that i don't get it why you need App ID and Guild ID , like we already creating bot and there no need of AppID . Also its a nice feature that you can test some command before lunch to global but why i how to change guildID that could works on every server?
in your src/register-commands.js
replace this
await rest.put(
Routes.applicationGuildCommands(
process.env.CLIENT_ID,
process.env.GUILD_ID)
{ body: commands }
);
put this instead
await rest.put(
Routes.applicationCommands(process.env.CLIENT_ID),
{ body: commands }
);
it should be fixed
hey i was working on this and when i hit the 5:56 minutes part i got discord is undefined cant find a solution to it?
found the issues
can someone help me, it say Routes.applicationGuildCommands not a function
For anyone having the error: 0.name[APPLICATION_COMMAND_INVALID_NAME]: Command name is invalid.
make the name between the strings LOWERCASE! name: 'Hey' is NOT gonna work. Instead, try name: 'hey'
Thx bro!
Dude no lie I scoured my code trying to figure this out... You're a legend 💯
Thank you~
There was an error: DiscordAPIError[50035]: Invalid Form Body
0.name[APPLICATION_COMMAND_INVALID_NAME]: Command name is invalid. I have that error pls help me
Nice video, but i have problem DiscordAPIError[50035]: Invalid Form Body
name[APPLICATION_COMMAND_INVALID_NAME]: Command name is invalid.
Can you help me solve this?
One of the commands you’re registering has an invalid name. Make sure it doesn’t have any space, only letters and make sure it’s all in lowercase. If all your command names are fine then check your options inside your commands to follow the same pattern. Options can however use “-“ in their names.
@@UnderCtrl You are the only one who really helped me with writing the bot, thanks so much !
@@UnderCtrlWhat do you mean by that?
Hello! Thank you so much for these tutorials. Something I noticed is that every time I add commands to my bot, I have to kick and reinvite it for the new commands to show up. Is there a way to have them automatically appear without a kick/rejoin?
Hey. So that's most likely a Discord caching issue with the desktop app. Instead of kicking the bot and re-inviting it, I suggest just refreshing your Discord using Ctrl + R (Cmd + R on mac) and you'll get updated commands.
@@UnderCtrl Thank you, I'll give it a shot!
you are the best
I had a error with the slash command:
DiscordAPIError[20012]: You are not authorized to preform this action on this application.
your token is wrong
hey bro ! fantastic vid, it really elps me out as im trying to learn coding, but i have a question, when i write the
description: '....' it shows a problem and i cant figure it out, could u please help me?
the ... means there is more text than it can show on the description section of the avatar. try removing the newlines.
when I run the command node src/register-commands.js it doesn't do anything. No errors, no / commands on my server. nothing. Just keeps running like nothing happened.
Try restarting the terminal and try again. If the issue still persists please join my Discord and share your issue there: discord.underctrl.io
Idk if you still have this problem. But you most likely forgot to add a (); at the end of the async function.
hey so when i try to run the commands or check on it like node register-commands.js it does not work and the was same before when I have try to run the bot same does not work until i use client.login('');
and I closed the .env (deleted) when I open a .env channel and use TOKEN = .... that doesn't work
I hope you understand what I'm trying to explain
@UnderCtr
@Under Cntrl
broo i prmblmm my slash code is registering but after that insted of registerd successfully There was an error: Error: Expected token to be set for this request, but none was present this is showing wt is prob
I have that same problem, havent figured it out yet
You need to be in the folder before the src folder and then, do: node src/register-commands.js
How can i fix it?:
There was an error: DiscordAPIError[0]: 405: Method Not Allowed
applicationGuildCommands, I forget add the 's' at the tail , now is working
@@LIL_13EN you saved me bro
any idea why each command gets registered twice indentically?
bro,you're a god.
did you have any udemy course? or any course besides youtube? i would like to pay damm
Thank you so much for the positive comment! 😊 I don’t have any courses yet but I am planning to create one which covers the Discord.js library.
@@UnderCtrl just have a quick question,how to you keep the bot online withouth need the pc?
You have to host it on a server. You’d usually rent a server for that
Can the index js send a slash command, even if there was no interaction initiated on the server? And will the Discord server run the slash command sent? I run windows, so my intent is to set up a daily schedule in the windows scheduler, that would run the js file at a given time everyday
If you want to send some message some time of the day, you can instead fetch the channel and send a regular message. You don't have to use slash command interactions for that. Interactions are only triggered when a user interacts in some way with your Discord bot.
@@UnderCtrl Can the js fetch the channel and send a slash command? I have a particular slash command on a private channel that performs a function. Right now I end up doing that manually on the channel each day, but I want the js to do it for me instead.
@@jryer1 Yes, you can. If you want to find the channel by its id (get the id by right-clicking it in developer mode), then put this code (recommended if your bot is in multiple servers):
channel = client.channels.cache.find(ch => ch.id === 'your-channel-id')
If you instead want to find the channel by its name, enter this code (recommended if your bot is for one server):
channel = client.channels.cache.find(ch => ch.name === 'your-channel-name')
After this, you have to send the message using channel.send('This message was sent to its designated channel.')
Here's how I would write your full code:
// first, run npm install cron in your terminal
// at the top of your file
const cron = require('cron')
// this next piece of code goes inside whatever client ready event you have, whether it is client.once(Events.ClientReady,...), client.once('ready',...), etc.)
client.once('ready', (c) => {
console.log(`${c.user.tag} is online`) // you may have something like this in your client ready event
let scheduledMessage = new cron.CronJob('00 30 12 * * *', () => {
// The format is seconds minutes hours, so 00 30 12 would send a message at 12:30 (please note this adjusts for your timezone)
const channel = client.channels.cache.find(ch => ch.id === 'your-channel-id') // or channel = client.channels.cache.find(ch => ch.name === 'your-channel-name')
// in the above line, if. you define your client as Discord.Client at the top of your code, replace "client" with Discord.Client
channel.send('This message was sent at 12:30!');
});
scheduledMessage.start()
});
And that should be all! If you have any follow-up questions, please reply to this comment. Sorry for the long reply, but hope this helped!
@@jryer1 you could make a seperate file that does what the slas command does and then shedule the file to run eveyday using whatever you want
You can help me? I have a error.
ReferenceError: procces is not defined
i know this is kinda old but i cant seem to get my token to work, it says TypeError: (intermediate value).setToken(...) is not a function 😞
const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);
Hello i tried the .env but idk it just throws error of invalid token
save all your files by going through every file and hitting ctrl + s
how to remove a registered slash command ?
i tried everything but i couldnt get the src/register-command.js to respond i have the exactly same code as you and it doesnt respond. i need a bit help
Your .env file might not be where it should or something of the sorts, where `process.env.thingy` is used, try using the bare "strings!"
Hey in minute 5.56 i get an typeError .setToken isnot a function please help me solve it
I got it too and adding a semicolon behind the line with the setToken function fixed it
@UnderCtrl it says for me that setToken(...) is not a function. I copied your code from Github so that means its the same as your, please help
I had the same issue, make sure that when defining `const rest` that there is a semicolon(;) at the end of the declaration
these videos are very helpful but its so frustrating that in only a year everything updates to where it keeps throwing errors
Why do i keep getting this?
node:internal/modules/cjs/loader:1093
throw err;
^
Error: Cannot find module 'C:\Users\justd\Downloads\NovaBotBeta\src
egister-commands.js'
at Module._resolveFilename (node:internal/modules/cjs/loader:1090:15)
at Module._load (node:internal/modules/cjs/loader:934:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
at node:internal/main/run_main_module:23:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v19.8.1
dont type nodemon just type node src/the name of your file. this worked for me
@@RoganShorts2715 ok ill try it, thank you
every time i run .setToken, i get given an error, and not processed thru console.log. im using discord.js version 14.14.1
If the error is something like: "setToken is not a function" then add the semi colon to the end of it. (I know I'm late.)
@@BANGPOWBANGPOWPOWThank you so much! I was stuck here for like 10 minutes.
I get the following error: An error has occured: DiscordAPIError[50035]: Invalid Form Body application_id[NUMBER_TYPE_COERCE]: Value "undefined" is not snowflake.
Does anyone know how to fix this?
After Troubleshooting for a moment, My issue was the env file was not saved. Make sure you save the env file so that the functions are actually retrievable.
@@robotmercenary8844DUDE I LOVE YOU
@@robotmercenary8844saved me so much
how do i get the design like you?
thanks but I don't have handelcommands,handleevents folders :(
You don't need it for this video. We cover it later in the series.
My commands won't show up, someone help me out pls?
hey, can other users use these commands as well? i mean does bot reply them too?
Yes
When i run this it says MODULE_NOT_FOUND
Could i please have help
thanks
Quite a few reasons why that could happen. Please join my Discord for help: discord.underctrl.io
@@UnderCtrl alright thank you
what do i do when it says ReferenceError Route is not difined
same, did u fix?
Im having a problem it says:
There was an error: DiscordAPIError[0]: 405: Method Not Allowed
applicationGuildCommands not applicationGuildCommand
Bruh, it keeps saying settoken is not a function. Y'know anyway to fix this? i've been scratching my head for the past 2 hours
fixed it following me sending this, probably spoke too soon
Hey where do you find the guild Id ??
this is your discord server ID
I made this mistake too. You need to right click the discord server name. not left click. It looks like Two seperate menus but they look increadibly similar
Thanks for the last video was really helpful!
and this is by far the best video yet on how to make discord bots!
so right now im coming across this error when i type in "node src/register-commands.js"
Registering Slash Commands...
There was an Error: DiscordAPIError[50035]: Invalid Form Body
name[APPLICATION_COMMAND_INVALID_NAME]: Command name is invalid
What should I do to fix it? (I tried looking it up i wasn't able to find my answer so I thought maybe you would know.
One of your commands has an invalid name. Make sure it doesn’t have uppercase, spaces or any other special characters.
how do i make the bot respond with the interaction author username?
interaction.reply(`Hey there ${interaction.member.username}!`)
@@UnderCtrl thanks! How do I define the username? Its responding Hey there undefined
it keeps saying invalid token provided when I know its the right token
fixed
it sends me an empty message box
I dunno why, but it didn't work for me :(
I have error method not allowed
im getting this too
ill update if i find a fix
how to get the src file???
The src folder is what we created in the first video. It's not important if you already have an existing project. You can just create all your files and folders in your current directory. If you do choose a src folder make sure to change "main" in package.json to "src/index.js"
I am getting multiple instance for single input
user input: Hi
Bot Output: Hey
Hey
Hey
That is probably because you have multiple terminals open
@@UnderCtrl thanks I got solution from your discord.
why do we need the guild id ?
To register commands to that specific server only. Global commands can take time to register
undefined value in guild id and user id wtf
also the .settoken isn't a function no more.
Everything is going well, but i am experiencing a problem
(async() => {
^
TypeError: (intermediate value).setToken(...) is not a function
at Object. (C:\Users\294ad\Captain's Utilities\src
egister-commands.js:13:1)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47
Use client.application.commands.set(commandsArray);
I experienced the similar problem, but I figured out how to fix it:
const rest = new REST({ version : '10'}).setToken(process.env.TOKEN);
You must have corrected it or something by now.
This happened to me, I missed the set of parentheses at the very end
spent 30 min on this error, the semi colon is required when defining rest.
this works:
const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);
this doesnt:
const rest = new REST({ version: '10' }).setToken(process.env.TOKEN)
I tried this code but there is an error like this:
🔴 Error is: DiscordAPIError[50035]: Invalid Form Body
Can someone help!
I solved the problem anyways
please help me with that as i have the same problem
um.. ;-; that's not exactly working