You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Discord.JS v13斜杠命令运行15分钟报Invalid Webhook Token错误求助

首先明确结论:斜杠命令交互对应的Webhook令牌有效期为15分钟是Discord官方的固定规则,该说法属实,且没有办法在交互生成后手动刷新这个令牌。你代码中设置的定时循环总运行时长为60分钟,远超出15分钟的令牌有效期,因此触发令牌失效报错。

可行解决方案

  • 方案1:保留单条消息更新效果,转用普通频道消息编辑接口
    首次交互回复时获取返回的消息对象,后续所有更新操作直接调用频道消息编辑方法,不受交互令牌有效期限制,示例修改如下:

    client.on('interactionCreate', async interaction => {
        if (interaction.commandName === 'command') {
            try {
                let time = 60;
                let current = 0;
                // 回复时加fetchReply参数拿到实际发送的消息对象
                const replyMsg = await interaction.reply({embeds: [myembed], fetchReply: true});
                const channel = interaction.channel;
    
                let interval = setInterval(async () => {
                    try {
                        current++;
                        // 替换interaction.editReply为频道消息编辑
                        await channel.messages.edit(replyMsg.id, {embeds: [newembed]});
                        if(current == time)
                        {
                            await channel.messages.edit(replyMsg.id, {embeds: [newembed], components: [button_row]});
                            clearInterval(interval);
                        }
                    } catch(err) {
                        console.error('循环执行出错:', err);
                        clearInterval(interval);
                    }
                }, 60000);
            } catch(err) {
                if (!interaction.replied) {
                    await interaction.reply({embeds: [error]});
                }
            }
        }
    });
    

    该方案与原交互逻辑体验完全一致,仅需要机器人拥有频道内编辑消息的权限即可正常运行。

  • 方案2:你当前使用的interaction.channel.send()发送独立新消息的方案也可正常使用,若不需要持续更新同一条消息可以继续沿用,注意做好异常捕获避免崩溃即可。

额外注意

交互令牌过期后所有interaction.reply、interaction.editReply、interaction.followUp相关方法都会失效,超过15分钟的后续操作必须全部转为普通频道消息操作,同时建议给所有异步回调加try/catch包裹,避免单次请求错误直接导致进程崩溃。

内容的提问来源于stack exchange,提问作者ChaosQK

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 01:15:04