简体   繁体   中英

Slash commands not listing in console (discord.js)

I recently have been using discord.js to make slash commands but made a typo. Instead of making it say /help, I made it say /hlep. I tried to find its its id by using console.log(client.api.applications(client.user.id).commands.get()) , but it just said Promise { <pending> } in console and I don't know what to do.

As client.api.applications(client.user.id).commands.get() is asynchronous , it returns a Promise instead of an object.

From MDN:

A Promise is a proxy for a value not necessarily known when the promise is created. It allows you to associate handlers with an asynchronous action's eventual success value or failure reason.

A pending promise can either be fulfilled with a value or rejected with a reason (error).

Either use the .then function, to run code when the Promise fulfils:

client.api.applications(client.user.id).commands.get().then((result) => {
    console.log(result);
    // You may also put other code here to be run when it is fulfilled.
});

... or use it in an asynchronous function like so:

let result = await client.api.applications(client.user.id).commands.get();
console.log(result);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM