javascript - (节点: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:(中间值)不可迭代
解决方案
@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 });
推荐阅读
- java - 如何仅对 NatTable 中选定的视口层行数禁用“行选择”?
- python - 我可以使用函数式 API 在模型中使用循环吗?
- sql - 选择最大日期和时间
- python - 舍入数据框列时处理字符串值
- opengl - 当厚度 > 1 时填充 GL_LINE_STRIP 间隙会破坏透明度
- jquery - 在保持相对的同时使侧边栏在向下滚动时保持粘性
- react-native - React Native 的 Jest 测试快照可视化
- javascript - javascript通过路径数组到达元素
- c# - 如何使用 refit 库实现 Jwt 身份验证并让它在一定时间内缓存不记名令牌?
- hyperledger-explorer - 无法启动 Hyperledger Explorer