rawError: { message: '未知交互', code: 10062} 在discord.js v14

问题描述 投票:0回答:1

当我运行其他所有命令时,它工作得很好,但是当我使用 /rank 时,它显示“未知交互”错误,该错误仅在错误处理没有任何问题时发生,例如有效的用户 ID 和等级id,但当它出现时,它工作得很好。

我不喜欢 try{},所以如果有办法使用 .try 来修复它,请告诉我

代码:

if (interaction.commandName === "rank") {
    const tuser = interaction.options.getNumber("targetuser");
    const trank = interaction.options.getNumber("targetrank");

    noblox
      .changeRank(5156922, tuser, trank)
      .then(async () => {
        const username = await noblox.getUsernameFromId(tuser);
        const grn = await noblox.getRankNameInGroup(5156922, tuser);
        interaction.reply(
          `The rank of ${username} has been updated and they have been ranked to **${grn}**`
        );
      })
      .catch((error) => {
        console.error(error.stack);
        interaction.respond({
          content: `Something went wrong, Here is what can have gone wrong: \n\n- **The user id does not exist or isn't in the group**\n- **The rank number does not exist**\nPlease double check the fields. Thank you!`,
          ephemeral: true,
        });
      });
  }

错误:

rawError: { message: 'Unknown interaction', code: 10062 },
  code: 10062,
  status: 404,
  method: 'POST',
  url: 'https://discord.com/api/v10/interactions/1193921932316377109/aW50ZXJhY3Rpb246MTE5MzkyMTkzMjMxNjM3NzEwOTpjRkVPQTZlSzUxNE1RQmxzM0M4Y3h1TFN6VU45ZmpkVEtXTXk2cThCalpGUWtiSXZHVnVtVVBxTzR2U01HcDZRb0RRT3RxeXAwYmZxTlpicDZIMjAwb3RreFQ4Wm5CaEN4MXVKdmx1cGZpZGRWdW5YUXo4Q2Zxd3NDZmNOM05WNQ/callback'
}

我正在尝试修复 /rank 问题,请告诉我。

javascript node.js discord discord.js
1个回答
0
投票

响应斜杠命令时,您有 3 秒的时间发送回复。如果您需要更多时间,请推迟回复。您可以使用

interaction.deferReply()

来做到这一点

更新代码:

if (interaction.commandName === "rank") {
    await interaction.deferReply(); // Used await for now, depending on whether you're using async/await or not you'd have to change this
    const tuser = interaction.options.getNumber("targetuser");
    const trank = interaction.options.getNumber("targetrank");

    noblox
        .changeRank(5156922, tuser, trank)
        .then(async () => {
            const username = await noblox.getUsernameFromId(tuser);
            const grn = await noblox.getRankNameInGroup(5156922, tuser);
            interaction.reply(
                `The rank of ${username} has been updated and they have been ranked to **${grn}**`
            );
        })
        .catch((error) => {
            console.error(error.stack);
            interaction.respond({
                content: `Something went wrong, Here is what can have gone wrong: \n\n- **The user id does not exist or isn't in the group**\n- **The rank number does not exist**\nPlease double check the fields. Thank you!`,
                ephemeral: true,
            });
        });
}
© www.soinside.com 2019 - 2024. All rights reserved.