首页 > 解决方案 > (节点:31436)UnhandledPromiseRejectionWarning:TypeError:(中间值)不可迭代

问题描述

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

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:(中间值)不可迭代

标签: javascriptdiscord.js

解决方案


@Utkarsh 是对的。

当我使用 BlubirdPromisifyAll为 pacakge 添加异步功能时,我遇到了同样的问题request

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 });

推荐阅读