我會盡力解釋這一點,但是,這有點令人困惑。這是我執行斜杠命令的代碼。
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction, Servers, Tickets, client);
} catch (error) {
console.error(error);
await interaction.reply({ embeds: [errorEmbed], ephemeral: true });
}
});
如果我把它放在client前面Servers,它允許我在其他命令中使用它,但是,如果我把它放在后面,比如 after Tickets,它就不起作用了。當我移動Tickets或Servers到最后我不能再使用命令中的那些時,也會發生這種情況。關于為什么會這樣的任何想法?
uj5u.com熱心網友回復:
如果您運行command.execute(interaction, Servers, Tickets, client),則每個命令檔案中的引數順序必須相同。即使您不需要變數Servers或Tickets,如果您想使用client,它也是第四個引數。
最好傳遞一個物件:
command.execute({ client, interaction, Servers, Tickets })
在您的命令檔案中,解構物件以選擇您需要的物件:
async execute({ client, interaction }) {
// ...
async execute({ Servers }) {
// ...
這樣順序就不再重要了,但是您仍然需要使用大括號更新每個命令檔案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/497307.html
標籤:javascript 节点.js 不和谐 不和谐.js
上一篇:持續時間不適用于所有行
