(节点:31436)UnhandledPromiseRejectionWarning:TypeError :(中间值)不可迭代

时间:2019-10-09 13:00:26

标签: javascript discord.js

我不知道,但是我发现错误如何解决?

async execute(message, args) {
        if (!args[0]) return message.channel.send('Укажи название песни.');
        if (!message.member || !message.member.voiceChannel) return message.channel.send('Нужно зайти в голосовой канал.');

        const query = args.join(' ');
        const [song] = await bot.getSongs(`ytsearch: ${query}`);


        if (!song) return message.channel.send('Ничего не найдено...');

        const player = await bot.player.join({
            guild: message.guild.id,
            channel: message.member.voiceChannelID,
            host: bot.player.nodes.first().host
        }, {selfdeaf: true});

        if (!player) return message.channel.send('Я не могу зайти в канал.');

        player.play(song.track);

        player.once('error', () => {});
        player.once('end', async data => {
            if (data.reason === 'REPLACED') return;
            message.channel.send(`Песня **${song.info.title}** закончилась.`);
            await bot.player.leave(message.guild.id);
        });

        return message.channel.send(`Сейчас играет: **${song.info.title}**`);
    }

错误:(节点:31436)UnhandledPromiseRejectionWarning:TypeError :(中间值)不可迭代

1 个答案:

答案 0 :(得分:0)

@Utkarsh 是对的。

我刚刚在使用 Blubird 的 PromisifyAllrequest pacakge 添加异步函数时遇到了同样的问题。

import Promise from 'bluebird';
import request from 'request';

const requestAsync = Promise.promisifyAll(request);


async function x() {
  const [_res, body] = await requestAsync.getAsync({
    uri: 'http://google.com',
  });
}

UnhandledPromiseRejectionWarning: TypeError: (intermediate value) is not iterable 的发生都是因为 requestAsync.getAsync 没有返回数组。

尝试分配给单个变量或考虑其他类型的异步函数,在我的情况下,它是:

const requestAsync = Promise.promisifyAll(request, { multiArgs: true });