(SOLVED) Issues With Slash Command Integration

I followed the tutorial in the documentation about creating slash commands, but I've run into a couple of issues. 1) When I run my bot I get the console message saying Successfully reloaded application (/) commands, but they don't work because my bot doesn't actually show as online despite me using bot.login(MY TOKEN). 2) Uncommenting out the line that says commands.push(command.data.toJSON()) gives me the error depicted in the attached image. According to npm, I am using version 14.3.0 of discord.js, and - as far as I can see - I have followed the tutorial exactly as shown on the website. I am using v18.7.0 of Node. I'm a complete novice at JavaScript, so this is all very complicated for me; apologies in advance if it turns out I've made a screamingly obvious error that my tiny mind couldn't comprehend. The code I'm using can be found on Pastebin at https://pastebin.com/pSM10ex6, and the code I am using for the slash command (the basic /ping) is at the bottom. If you need any further details, please let me know.
9 Replies
d.js docs
d.js docs2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
GeodesicDragon
I updated the code with that block, but now I keep getting this when trying to start the bot. It shows as online, but the /ping command doesn't work.
GeodesicDragon
I've updated the Pastebin with the new code. I have no idea what that means. (Reminder that I'm new to this.)
d.js docs
d.js docs2y ago
guide Creating Your Bot: Individual command files First, create a commands/ping.js file for your ping command: read more
GeodesicDragon
Got it working by looking at the code on GitHub. Thanks for the help. Actually, there's something else. I'd like to have a single slash command that does different things depending on the channel it is used in. Is this possible?
Zeroknights
Zeroknights2y ago
Yes Use if, else if … interaction.channel.id
GeodesicDragon
Ah, right, that's what I was missing. Thanks.
Zeroknights
Zeroknights2y ago
Will give you the id of the channel the command was executed in Or switch(interaction.channel.id) {}