How would I fix this code?
Read the text document for it
143 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!I cant send my version as im using a host that doesnt allow it
it claims that there is no command as "verify" or any other command on either bot when there is
why do you have 2 client instances in there
Thats prone to cause issues
We are hosting 2 different bots.
Have a separate project per bot
Not cram them in 1 single file
Also show the entire error message, not just the description of it
Then its more time I would need to watch ads for and more craziness for me
One minute
Then get a proper host
Not a shady free one, thats just gonna cause more issues
But I love giving my discord bot token to a hosting company that is farming bot tokens to raid/spam millions of users simultaneously
erm
It's a risk you run with a free host. If you're not paying them, then you're not a customer. You're a product. So your code (most importantly, your token) shouldn't be thought of as secure.
They might be scraping and selling bot tokens to make money off their free "users"
and i refuse to pay for bots that will only be used in a few servers

but when i go to the command file for that command

..
.
Be patient. No one is obligated to help you.
what is the issue you are having exactly?
Commands are not working with 2 bots in 1 index.
you're using the same commands for both bots?
No im using 2 different folders for commands
bc they are for 2 different servers
how about the events?
The events work
the commands dont
the bots start and register the commands though
you shouldnt register your commands every time you start your bot though. And registering is separate.
Log to see if they actually get added to your commands collection
How could i proceed with this?
to log?
your command registering should be separate files which you only run when you add or edit commands
to debug your commands setting, thats basic js and should be common knowledge
They are different files
indeed they are, command registering is meant to be separate
and has nothing to do with handling or setting it into client.commands
which is where your issue is
oOk so should i log to see if they are getting detected?
yes
Ok!
Let me do that rq.

Looks like you're still updating your commands every restart
Srarted refreshing 12 application (/) commands.
That should be in a completely different launch script like npm run deploy
rather than npm run start
the issue is that my host doesnt allow me to run npm.
Just run the script manually on your own computer then push the update to the bot. It doesn't matter who/where the "deploy" script is run, it just has to be the same commands and the same token. As what you're doing is sending a list of commands to Discord for them to populate in the app
ok so if i do that this should be fixed?
No. Because as Vinny said, your problem is with your caching of commands to
client.commands
or with your handling of interactionCreate events
This is just to not get blocked from Discord for API spamso if I’m understanding this correctly it’s something with my command handler?
yes, your issue is located either in the function where you retrieve the files or in your interactionCreate event
:SA_pepemusic:
what Samtino told you to do has nothing to do with your actual issue, it was just a concern for you to avoid getting blocked from the Discord API because if you register automatically your slash commands on every startup you will end up banned from registering them again for 24 hours if im not wrong
also, your
handleInteraction
function is async and you are not implementing await
when you call it on both interactionCreate
events for both clientsSo that might be my problem?
maybe yes
try first by adding
await
in front of handleInteraction
on both interactionCreate
eventsI’ll try that when I get a chance.
https://sourceb.in/8mM6yGcBr5 - still printing the exact same thing
what are you printing?
its printing the following and not responding: "No command matching (INSERT COMMAND NAME HERE) was found on (INSERT BOT NAME HERE)
in that case the issue is in your
loadCommands
function
@TheActualGamer1YT
You're not running any promises in the function, so remove itsame thing happens.
hmmm
are you sure there is
data
and execute
in your commands?yes
one sec i could send you the command im runninf
yeah
one minute
let me send it over
alr
does this actually print?
when you load the commands
No
but it does show up
in discord
yeah
can you show me your deply-commands.js?
like it shows up in the discord servers but it never prints
one moment
yeah the commands register but this
does not print?
no
i think i see why
do you have sub folders in your "commands" and "winter-commands" folders?
like commands --> info --> commandName.js
yes
okay so
the issue you are having
indeed
is that you see the "commands" folder that you are finding with the
loadCommands
function?yes
you are directly looking for files that end with ".js" inside the "commands" main folder, but as you have sub-folders inside that "commands" folder then you can't find them like that
ohhhhhhhhh
yeah
you are looking for stuff that don't exist in the "commands" folder
instead, you should look for folders inside the "commands" folder
and for each of these folders inside the "commands" folder look for files that end with ".js"
How would I do that
you create another foor loop for the retrieved sub-folders
hold on
this is retrieving folders instead of files
start by removing the .filter
make it only fs.readdirSync(commandsPath)
and uh obviously change the name of the constant to "commandFolders" instead of "comandFiles"
Like this?
https://sourceb.in/wzsefS2D1U
change
const file
to const folder
remove the filter from "commandFolder"
so it would be
yeah
then
you get the path to the obtained folder from
const folder
no
would change to:
const filePath = path.join(commandFolders, folder);
const command = require(filePath);
right
yes
now
remove this whole block, but you'll need it for later
k
then, below that, create a new
for (...)
loop that iterates the folderk
no actually
@TheActualGamer1YT
below that, add a constant where you use
fs
to read the folderPath
and filtering it in order to only get files that end with ".js"
then you create the for loop that iterates through the created constant
my bad for the confusionits fine!
https://sourceb.in/LYtvnPJuzE then make the for loop?
this should be:
instead
then, yeah, you make the for loop
what would the for loop check for
it would check for files inside of your
files
constant
do you know how to do the for loop?i think
try and ill tell u if its correct
instead, by that you are going through every file of
files
inside the for loop, you put this
don't forget to define "filePath" beforeoh ok
please ping me when you are done because im not on the app
k
@35k._a
https://sourceb.in/ue0BtzTYjw
you need to create a constant called "filePath" inside the for loop i gave you and put it inside require()
to do so you do the same thing as you did for "folderPath", using the
path.join
method@35k._a
like this?
https://sourceb.in/QJUQF7Gop3
hold on
k
replace the
filePath
inside the parenthesis with file
also, ive noticed something elsek
replace
commandFolders
with commandsPath

commandFolders is an array, and you want to put strings inside of the
join
method
after doing all that, you're good to golike this?
https://sourceb.in/w8SoiLaDk8
you need to do this lastly
replace the
commandFolders
inside the parenthesis of the folderPath
constant with commandsPath
line 28you're good to go now
try now
ok!
lmk how it goes
alright
Worked as I can see! Thanks a lot
no problem
uh just one thing
ye
i hardly suggest you to get documented about these
for (...)
loops and more topics about javascript before doing anything else so you know the basics of the language, you may view these links covering these loops:
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration
- https://www.youtube.com/watch?v=c5a4sNshBA4 (for ... in
, for ...of
loops, not covered on the video below) - 2 min video
- https://www.youtube.com/watch?v=ZOQYIWLngSU - 5 min video
oh no hold on
i got confused w the links lolAlright!
lol
i tell u that so you dont face these kind of issues again
because your issue today was because due to these for loops
oh ok
also check #resources for more documentation sites
Alright thanks a lot!
np
im having issues again this time with it not printing anything out if something went wrong: https://sourceb.in/JnyWru0Z27
running any command is not working, here are the logs as well:
Unknown User•5h ago
Message Not Public
Sign In & Join Server To View
registering them in the deploy-command files i think
Unknown User•5h ago
Message Not Public
Sign In & Join Server To View
its worked until i added the button handlers
Unknown User•5h ago
Message Not Public
Sign In & Join Server To View
it only runs that if i manually restart it (it doesnt go down and up it stays up unless i restart it, the host goes down, or i don't have enough coins on my host to pay.)
^
Unknown User•5h ago
Message Not Public
Sign In & Join Server To View
like what, ive tried the:
that didn't tell me anything
Unknown User•5h ago
Message Not Public
Sign In & Join Server To View
If you aren't getting any errors, try to place
console.log
checkpoints throughout your code to find out where execution stops.
- Once you do, log relevant values and if-conditions
- More sophisticated debugging methods are breakpoints and runtime inspections: learn moreafter i looked closer, i found that i forgot the interactioncreated event lol
Unknown User•5h ago
Message Not Public
Sign In & Join Server To View
its fine!
i didn't either lol