#Having trouble trying to set up slash commands.

103 messages · Page 1 of 1 (latest)

golden mountain
#

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..

deft bearBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • 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
golden mountain
#

i can send some of the scripts in the bot hold on..

crisp lakeBOT
#

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

paper steppe
#

We recommend this official guide so youre not relying on outdated YT vids

golden mountain
#

well i put 2023 in the search

#

i can see what i can do..

paper steppe
#

the message event was replaced with the messageCreate event
deprecated in v13 and fully removed in v14

golden mountain
#

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???

paper steppe
golden mountain
#

oh

paper steppe
#

and subfolders aren't files, so they dont end with extensions

golden mountain
#

ok so you want me to change the message to messagecreate?

paper steppe
#

Yes.

#

the event name, not the variable name

golden mountain
#

client.on("message", message => { Is this the event?

golden mountain
#

yep it was

#

now do I follow the guide?

paper steppe
#

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

golden mountain
#

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

golden mountain
#

oh

paper steppe
#

it's a folder
folder structures aren't like C.js/Users.py/Owner.md/Desktop.json

golden mountain
#

ya

#

so what am i post to do??? only thing did is create a commands folder and now i cna't do anything\

paper steppe
#

"the guide" is an entire website

golden mountain
#

i will look again

#

that is the start

paper steppe
#

Ok now keep following

golden mountain
#

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?

#

??

paper steppe
#

if thats what the guide says to do, then do it

golden mountain
#

well we already made it in the index.js and it doesnt mention that..

#

?

#

theres no slash command showing in it

#

Hello??????

#

Are you going to answer?????

vocal parrot
#

@golden mountain 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.

golden mountain
#

this what i did..

vocal parrot
#

Yes you did that part correctly

#

But there's more you have to do

#

And it's all in the guide

golden mountain
#

is that the last remaining bits..

#

oh

#

no nvm

#

i see it

#

so i have to do those 2?

#

or those optional?

vocal parrot
#

you completed Creating slash commands

golden mountain
#

command handleing

vocal parrot
#

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

golden mountain
#

the server and user?

#

command?

vocal parrot
#

after you complete those 2 sections, the user will see the slash command in their text box, if thats what you mean

golden mountain
#

ohhhh

#

ok i can see what i can do..

vocal parrot
#

Good luck

#

make sure you read those sections thoroughly

golden mountain
#

alright

#

i might be asking questions through on it i hope thats fine..

vocal parrot
#

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

golden mountain
#

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); ?

vocal parrot
#

yes

golden mountain
#

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?

vocal parrot
#

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

golden mountain
#

wdym?

#

well its my first tme codeing soooo..

vocal parrot
#

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

golden mountain
#

so i have to do all of that..

#

alright then..

vocal parrot
#

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

golden mountain
#

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?

vocal parrot
#

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

golden mountain
#

ik im just confused how to set it up

#

cuz i got the rest of stuff in there