斜杠命令未在控制台中列出 (discord.js)
Slash commands not listing in console (discord.js)
我最近一直在使用discord.js来制作斜杠命令,但打错了。我没有让它说 /help,而是让它说 /hlep。我试图通过使用 console.log(client.api.applications(client.user.id).commands.get())
找到它的 ID,但它只是在控制台中显示 Promise { <pending> }
,我不知道该怎么做。
因为 client.api.applications(client.user.id).commands.get()
是 asynchronous, it returns a Promise 而不是对象。
来自 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).
要么使用.then
函数,当Promise实现时运行代码:
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.
});
... 或像这样在异步函数中使用它:
let result = await client.api.applications(client.user.id).commands.get();
console.log(result);
我最近一直在使用discord.js来制作斜杠命令,但打错了。我没有让它说 /help,而是让它说 /hlep。我试图通过使用 console.log(client.api.applications(client.user.id).commands.get())
找到它的 ID,但它只是在控制台中显示 Promise { <pending> }
,我不知道该怎么做。
因为 client.api.applications(client.user.id).commands.get()
是 asynchronous, it returns a Promise 而不是对象。
来自 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).
要么使用.then
函数,当Promise实现时运行代码:
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.
});
... 或像这样在异步函数中使用它:
let result = await client.api.applications(client.user.id).commands.get();
console.log(result);