discordjs / guide

The official guide for discord.js, created and maintained by core members of its community.
https://discordjs.guide
MIT License
1.57k stars 2.31k forks source link

Slash commands guide doesn't work #1377

Closed havaka closed 1 year ago

havaka commented 1 year ago

Describe the bug

I was following the official slash commands guide, and it doesn't work. Bot is just turning on and slash commands are not appearing I tried many times, and I can't understand what am I doing wrong

To Reproduce

Copy all code from two files ( for example, ping.js and index.js) and try to start bot. It starts, but commands just won't show.

Screenshots

No response

Device (please complete the following information)

discord.js: 4.7.1 node.js: 16.17.0

Additional notes

No response

thegame4craft commented 1 year ago

i can confirm this. after looking into the guide, my code and this repo, it cannot work, because deploy-commands.js isn't called which sends all command registration stuff to the discord api. So that means that discord doesn't know that you want to register slash commands

following: https://github.com/discordjs/guide/tree/main/code-samples/creating-your-bot/command-deployment

almostSouji commented 1 year ago

Please follow the actual guide. We do cover this approach (and why we recommend registering files separately in-depth at https://discordjs.guide/creating-your-bot/command-deployment.html#command-registration

Slash commands only need to be registered once, and updated when the definition (description, options etc) is changed. As there is a daily limit on command creations, it's not necessary nor desirable to connect a whole client to the gateway or do this on every ready event. As such, a standalone script using the lighter REST manager is preferred.

This script is intended to be run separately, only when you need to make changes to your slash command definitions - you're free to modify parts such as the execute function as much as you like without redeployment.

You will have to do just that, run the file when you apply changes and want to commit them to Discord.