【发布时间】:2021-11-12 00:55:18
【问题描述】:
我最近在 node.js 中使用 Discord.JS 库制作了一个冷却不和谐机器人,因为我想使用新的 Discord.JS v13 来执行 Slash 命令。结果我的循环出错了
DiscordAPIError: Invalid Webhook Token
我在交互时收到了 editReply 错误。
这是完整的错误
C:\Users\Administrator\Desktop\Discord Lab Countdown brokers\node_modules\discord.js\src\rest\RequestHandler.js:298
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Invalid Webhook Token
at RequestHandler.execute (C:\Users\Administrator\Desktop\Discord Lab Countdown brokers\node_modules\discord.js\src\rest\RequestHandler.js:298:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (C:\Users\Administrator\Desktop\Discord Lab Countdown brokers\node_modules\discord.js\src\rest\RequestHandler.js:50:14)
at async InteractionWebhook.editMessage (C:\Users\Administrator\Desktop\Discord Lab Countdown brokers\node_modules\discord.js\src\structures\Webhook.js:268:15)
at async CommandInteraction.editReply (C:\Users\Administrator\Desktop\Discord Lab Countdown brokers\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:139:21)
at async Timeout._onTimeout (C:\Users\Administrator\Desktop\Discord Lab Countdown brokers\commands\command.js:45:21) {
该命令可以正常工作,但机器人会在 15 分钟后崩溃。所以我读到令牌会在 15 分钟后过期??但我不知道那是不是真的,如果是,如何在循环运行时重新生成它?
这里是命令代码:
client.on('interactionCreate', async interaction => {
// ...
if (interaction.commandName === 'command') {
// ...
try {
// ...
let time = 60;
let current = 0;
await interaction.reply({embeds: [myembed]});
// ...
let interval = setInterval(async () => {
current++;
await interaction.editReply({embeds: [newembed]});
if(current == time)
{
// ...
await interaction.editReply({embeds: [newembed], components: [button_row]}); <--- error points here
clearInterval(interval);
}
}, 60000);
} catch(err) {
await interaction.reply({embeds: [error]});
}
}
});
我真的需要这方面的帮助,因为我在互联网上找不到任何关于它的信息,
非常感谢:D
编辑:我在 discord.js 文档中注意到斜杠命令不会在 15 分钟后过期,所以我只是推迟了命令的回复并使用普通消息而不是 interaction.channel.send()
【问题讨论】:
标签: node.js discord.js