Skip to content
Advertisement

Discord.js v13 REST API Guide Cat and Urban Issues

So i tried following the https://discordjs.guide/additional-info/rest-api.html guide before making my own. But I can’t get either to work.

Firstly with /cat it crashes and the console returns with:

JavaScript

And /urban works but no matter what term I enter it returns with NULL.

Here is the code, its nearly identical from the guides apart from the added SlashCommandBuilder and REST.

JavaScript

Advertisement

Answer

So for the cat command since there is a deferReply first we need to use editReply since deferReply counts as the first/initial reply.

JavaScript

I also added a .catch to the end of each await, this was just for testing however I recommend it.

Now with the urban command, the reason it is using null is since you don’t have the string option’s text. We can check for it by adding an if statement.

JavaScript

IMPORTANT: When you are building your slash command you are not setting a string option. In the commands array, when creating the second slash command called urban we will add the support for the string option there. (An example using the string option, discord.js guide all command options)

This is how we can do this:

JavaScript

If you would like to make the term input required, add .setRequired(true) which will not allow the command to be ran without entering the term to search.

Once you do that you should be all good! Tested the code and it’s working once that’s fixed

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement