簡體   English   中英

Discord.js 未定義 V13 播放器

[英]Discord.js V13 Player is not defined

我正在構建一個 discord.js v13.6.0 音樂機器人,除此代碼外一切正常

const { QueryType } = require('discord-player');
module.exports = {
    name: 'play',
    aliases: ['p'],
    utilisation: '{prefix}play [song name/URL]',
    voiceChannel: true,

    async execute(client, message, args) {
        if (!args[0]) return message.channel.send(`${message.author}, Write the name of the music you want to search. ❌`);

        const res = await client.player.search(args.join(' '), {
            requestedBy: message.member,
            searchEngine: QueryType.AUTO
        });

        if (!res || !res.tracks.length) return message.channel.send(`${message.author}, No results found! ❌`);

        const queue = await client.player.createQueue(message.guild, {
            metadata: message.channel
        });

        try {
            if (!queue.connection) await queue.connect(message.member.voice.channel);
        } catch {
            await client.player.deleteQueue(message.guild.id);
            return message.channel.send(`${message.author}, I can't join audio channel. ❌`);
        }

        await message.channel.send(`Your ${res.playlist ? 'Your Playlist' : 'Your Track'} Loading... 🎧`);

        res.playlist ? queue.addTracks(res.tracks) : queue.addTrack(res.tracks[0]);

        if (!queue.playing) await queue.play();
    },
};

當我使用此命令時,出現以下錯誤:

Unhandled promise rejection: ReferenceError: player is not defined

我是編程新手,對於任何愚蠢的錯誤感到抱歉,如果您需要任何信息,請隨時詢問

出現此類錯誤的可能性是通過在沒有 catch 塊的情況下拋出異步 function 或拒絕沒有 a.catch() 的 promise

你可能正在做:

  1. 您將代碼放在異步function 中以便使用await調用。
  2. 等待的 function 失敗。

解決方案是:

  1. 要么使用.catch()

    await returnsPromise().catch(e => { console.log(e) })

或者

2.使用try/catch塊


try {
  await returnsPromise()
} catch (error) {
  console.log('That did not go well.')
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM