【发布时间】:2021-10-30 05:41:06
【问题描述】:
所以我正在使用 discord.js 版本 12.5.3 来重建我不久前做的音乐机器人。我正在尝试使用斜杠命令,但是当我使用 guild.commands.set([commands]) 时,它说 guild.commands 未定义。这是我的那部分代码。
async function loadCommands(guild) {
try {
const commands = Array.from(client.commands).map(([name, command]) => {
let optionsArr =
command?.usage
?.replaceAll(/[>|\]]/g, " ")
.split(/ +/g)
.filter((option) => option !== "") || [];
return {
name,
description: command.description,
options: optionsArr.map((option) => {
let required = option.substring(1, option.length) === "<";
return {
name: option.substring(1, option.length),
type: "STRING",
description: option.substring(1, option.length),
required,
};
}),
};
});
await guild.commands.set(commands);
} catch (e) {
return e;
}
}
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}`);
client.guilds.cache.forEach(async (guild) => {
await loadCommands(guild);
});
});
【问题讨论】:
-
Guild.commands在 v12 中不存在 -
@theusaf 那么为什么我会在 VS Code 中获得 Intellisense 以及如何在 v12 中使用斜杠命令呢?它也在文档中
-
非常感谢您的工作!但是您也知道如何删除斜杠命令吗?
-
没有。但我怀疑你必须以某种方式使用
.delete而不是.post
标签: javascript node.js discord.js