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
d.js toolkit
d.js toolkit14mo ago
- 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 OP
~·N·~
~·N·~OP14mo ago
i can send some of the scripts in the bot hold on..
d.js docs
d.js docs14mo ago
guide Creating Your Bot: Creating slash commands Discord allows developers to register slash commandsopen in new window, which provide users a first-class way of interacting directly with your application. read more
Squid
Squid14mo ago
We recommend this official guide so youre not relying on outdated YT vids
~·N·~
~·N·~OP14mo ago
well i put 2023 in the search
~·N·~
~·N·~OP14mo ago
SourceBin
index.js
Instantly share your code with the world.
~·N·~
~·N·~OP14mo ago
i can see what i can do.. utility.js, utility.json, or utility.md?
Squid
Squid14mo ago
the message event was replaced with the messageCreate event deprecated in v13 and fully removed in v14
~·N·~
~·N·~OP14mo ago
not 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???
Squid
Squid14mo ago
this was in response to your index.js file you just sent
~·N·~
~·N·~OP14mo ago
oh
Squid
Squid14mo ago
and subfolders aren't files, so they dont end with extensions
~·N·~
~·N·~OP14mo ago
ok so you want me to change the message to messagecreate?
Squid
Squid14mo ago
Yes. the event name, not the variable name
~·N·~
~·N·~OP14mo ago
client.on("message", message => { Is this the event?
~·N·~
~·N·~OP14mo ago
yep it was now do I follow the guide?
Squid
Squid14mo ago
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
~·N·~
~·N·~OP14mo ago
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
Squid
Squid14mo ago
.
~·N·~
~·N·~OP14mo ago
oh
Squid
Squid14mo ago
it's a folder folder structures aren't like C.js/Users.py/Owner.md/Desktop.json
~·N·~
~·N·~OP14mo ago
ya so what am i post to do??? only thing did is create a commands folder and now i cna't do anything\
Squid
Squid14mo ago
. "the guide" is an entire website
~·N·~
~·N·~OP14mo ago
i will look again that is the start
~·N·~
~·N·~OP14mo ago
No description
Squid
Squid14mo ago
Ok now keep following
~·N·~
~·N·~OP14mo ago
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? ??
Squid
Squid14mo ago
if thats what the guide says to do, then do it
~·N·~
~·N·~OP14mo ago
well we already made it in the index.js and it doesnt mention that.. ?
~·N·~
~·N·~OP14mo ago
the code is not working... i did https://sourceb.in/aJCH1mDcxE
SourceBin
code
Instantly share your code with the world.
~·N·~
~·N·~OP14mo ago
theres no slash command showing in it Hello?????? Are you going to answer?????
Dim
Dim14mo ago
@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.
No description
Dim
Dim14mo ago
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.
~·N·~
~·N·~OP14mo ago
this what i did..
No description
Dim
Dim14mo ago
Yes you did that part correctly But there's more you have to do And it's all in the guide
~·N·~
~·N·~OP14mo ago
No description
~·N·~
~·N·~OP14mo ago
is that the last remaining bits.. oh no nvm i see it so i have to do those 2? or those optional?
Dim
Dim14mo ago
you completed Creating slash commands
~·N·~
~·N·~OP14mo ago
command handleing
Dim
Dim14mo ago
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
~·N·~
~·N·~OP14mo ago
the server and user? command?
Dim
Dim14mo ago
after you complete those 2 sections, the user will see the slash command in their text box, if thats what you mean
~·N·~
~·N·~OP14mo ago
ohhhh ok i can see what i can do..
Dim
Dim14mo ago
Good luck make sure you read those sections thoroughly
~·N·~
~·N·~OP14mo ago
alright i might be asking questions through on it i hope thats fine..
Dim
Dim14mo ago
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
~·N·~
~·N·~OP14mo ago
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); ?
Dim
Dim14mo ago
yes
~·N·~
~·N·~OP14mo ago
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?
Dim
Dim14mo ago
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
~·N·~
~·N·~OP14mo ago
wdym? well its my first tme codeing soooo..
Dim
Dim14mo ago
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
Dim
Dim14mo ago
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
~·N·~
~·N·~OP14mo ago
so i have to do all of that.. alright then..
Dim
Dim14mo ago
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
~·N·~
~·N·~OP14mo ago
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?
Dim
Dim14mo ago
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
~·N·~
~·N·~OP14mo ago
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

Did you find this page helpful?