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

Discord.js 14音乐Bot异常:skip()方法跳过当前曲+队列首曲

问题

基于Discord.js 14开发音乐机器人时,调用skip()方法本应仅跳过当前播放歌曲,但实际会跳过当前歌曲和队列中的第一首歌。已确认服务器播放队列内容正常,尝试过其他方法但希望使用skip()解决问题。

代码如下:

const { SlashCommandBuilder, EmbedBuilder} = require('@discordjs/builders')

module.exports = {
    data: new SlashCommandBuilder()
        .setName('skip')
        .setDescription('Skips the current song'),

    run: async ({client, interaction}) => {
        const queue = client.player.getQueue(interaction.guildId)

        if (!queue){
            return await interaction.editReply("No songs are currently playing")
        }

        const currentSong = queue.current
        queue.skip()
        
        await interaction.editReply({
            embeds: [
                new EmbedBuilder()
                    .setDescription(`${currentSong.title} has been skipped`)
                    .setThumbnail(currentSong.thumbnail)
            ]
        })
    }
}
解决思路与方案
  • 更新discord-player版本:部分旧版本的skip()方法存在逻辑bug,会错误跳过下一首。执行npm install discord-player@latest安装最新稳定版。
  • 排查重复触发逻辑:检查代码中是否有其他地方(比如playerSkip事件监听)重复调用skip(),导致二次跳过。
  • 明确跳过数量参数:尝试给skip()传入参数1,强制仅跳过当前曲目:
    queue.skip(1);
    
  • 验证队列状态:调用skip()前打印队列信息,确认结构正常:
    console.log(`当前曲目:${currentSong.title},队列剩余曲目数:${queue.tracks.length}`);
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 02:38:10