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