Having trouble trying to set up slash commands.
Hey I'm having trouble setting up slash commands I try looking up videos to help find how to set up slash commands but none of them are working I need help setting up slash commands..
59 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!
- ✅
Marked as resolved by OPi can send some of the scripts in the bot hold on..
We recommend this official guide so youre not relying on outdated YT vids
well i put 2023 in the search
i can see what i can do..
utility.js, utility.json, or utility.md?
the
message
event was replaced with the messageCreate
event
deprecated in v13 and fully removed in v14not what i was saying... it says Create a new folder named commands and a subfolder named utility is it utility.js, utility.json, or utility.md???
this was in response to your index.js file you just sent
oh
and subfolders aren't files, so they dont end with extensions
ok so you want me to change the message to messagecreate?
Yes.
the event name, not the variable name
client.on("message", message => { Is this the event?
yep it was
now do I follow the guide?
if you do, you should follow it from the start
don't just jump into the middle of it since you're missing most of the infrastructure
and what do you want me to do at the utility part it doesnt say hat kind of file it is
idk if its a .js .json or .md
.
oh
it's a folder
folder structures aren't like
C.js/Users.py/Owner.md/Desktop.json
ya
so what am i post to do??? only thing did is create a commands folder and now i cna't do anything\
.
"the guide" is an entire website
i will look again
that is the start
Ok now keep following
oh folders i was reading it wrong
So you want me to make a new .js in the subfolder name it ping.js and put the command from the index into ping.js?
??
if thats what the guide says to do, then do it
well we already made it in the index.js and it doesnt mention that..
?
the code is not working... i did https://sourceb.in/aJCH1mDcxE
theres no slash command showing in it
Hello??????
Are you going to answer?????
@Ranner like Squid said, the problem is that you're relying on message/messageCreate for handling commands, which while it is possible, is not the way that it is done now. If you want to create slash commands pay very close attention to the guide, especially these 3 pages in particular.
Notice how in the command handling section, there is piece of code that uses
Events.InteractionCreate
. At no point does the guide use Events.MessageCreate
. That's because you don't need that event for handling slash commands.
So just closely follow those three sections of the guide and read through them thoroughly. If you try combining your code with an old YouTube tutorial's code, it's just not gonna work.this what i did..
Yes you did that part correctly
But there's more you have to do
And it's all in the guide
is that the last remaining bits..
oh
no nvm
i see it
so i have to do those 2?
or those optional?
you completed Creating slash commands
command handleing
you still have to do the other 2 to get discord to recognize your slash commands and to get your bot to handle them
without those 2, the file does nothing
the server and user?
command?
after you complete those 2 sections, the user will see the slash command in their text box, if thats what you mean
ohhhh
ok i can see what i can do..
Good luck
make sure you read those sections thoroughly
alright
i might be asking questions through on it i hope thats fine..
And each section comes with its own git folder so you can see what the entire codebase is supposed to look like up to that point
and compare it with yours
ok so where do i put this in index?
const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.commands = new Collection();
?
do i put it before the client.login(process.env.token); ?
yes
ok
/home/runner/Purple-mooser-bot/index.js:18
client.commands = new Collection();
^
ReferenceError: Collection is not defined
at Object.<anonymous> (/home/runner/Purple-mooser-bot/index.js:18:23)
at Module._compile (node:internal/modules/cjs/loader:1376:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Module._load (node:internal/modules/cjs/loader:1023:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
at node:internal/main/run_main_module:28:49
Node.js v20.10.0
error
let me try this..
/home/runner/Purple-mooser-bot/index.js:20
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
^
SyntaxError: Identifier 'Client' has already been declared
at internalCompileFunction (node:internal/vm:77:18)
at wrapSafe (node:internal/modules/cjs/loader:1288:20)
at Module._compile (node:internal/modules/cjs/loader:1340:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Module._load (node:internal/modules/cjs/loader:1023:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
at node:internal/main/run_main_module:28:49
Node.js v20.10.0 nope
what does it mean by attaching a .commands property to your client instance
well really quick is there post to be a crash loop during this?
the thing is you're creating the same variable multiple times
You don't seem to have a very good understanding of JavaScript so I'd recommend using some of the resources that the guide provides to first learn JavaScript and then make a bot
wdym?
well its my first tme codeing soooo..
I'm just saying that those are common errors that have nothing to do with the library itself. The purpose of this topic is for djs questions but you're just asking basic js questions
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
so i have to do all of that..
alright then..
I'm not saying you have to master JavaScript but at least get a good understanding of the fundamentals
And make sure to google things as much as you can
so how long will this take a hour or something?
also ain't google wrong at times..
do you want me to swap to the other-js-ts thing?
I mean you can but the thing is people in this server are not your personal teachers. We can help with some small problems you might have but if its a series of problems because you don't know basic js, very few people will have the time or patience to help
So I would really recommend learning js first
ik im just confused how to set it up
cuz i got the rest of stuff in there
welp i guess i will just give up and mark this as solved