javascript - 我无法制作播放音乐的不和谐机器人
问题描述
机器人成功连接到语音频道,但没有从我输入的 URL 播放歌曲,代码为:
if(message.content.startsWith(prefix + "join"))
{
message.channel.send("Entrando a " + message.member.voiceChannel);
if (message.member.voiceChannel)
{
const permissions = message.member.voiceChannel.permissionsFor(message.client.user);
if (!permissions.has('CONNECT'))
{
return message.channel.send('No me puedo conectar a ese canal')
}
if (!permissions.has('SPEAK')) {
return message.channel.send('No puedo hablar en ese canal')
}
let connection = await message.member.voiceChannel.join();
let dispatcher = connection.playStream(ytdl('https://www.youtube.com/watch?v=PLRrL9OsAF8&t=18s'))
.on('start', () => {
message.reply('Empieza la musica');
})
.on('end', () => {
message.reply('Termino la musica');
message.member.voiceChannel.leave();
})
.on('error', error => {
message.reply('Error al intentar reproducir la cancion');
});
dispatcher.setVolumeLogarithmic(5 / 5);
}
else
{
message.reply('Tenes que estar dentro de un chat de voz');
}
}
谁能确定造成这种情况的潜在原因?
解决方案
据我所知,您使用的是 Discord.js V11,这不是推荐的版本(V12)
从文档看来,也许您必须将可选参数传递给 ytdl
// Play streams using ytdl-core
const ytdl = require('ytdl-core');
const streamOptions = { seek: 0, volume: 1 };
voiceChannel.join()
.then(connection => {
const stream = ytdl('https://www.youtube.com/watch?v=XAWgeLF9EVQ', { filter : 'audioonly' });
const dispatcher = connection.playStream(stream, streamOptions);
})
.catch(console.error);
如果这不起作用,可以在此处找到 Discord.js 的支持服务器。他们在 3 月正式迁移到 V12,但他们可能仍会帮助您
推荐阅读
- python - scikit-learn train_test_split 是否保留关系?
- java - 基于选择结果的基本锁定
- .htaccess - htaccess 文件中 https 的重定向规则不起作用
- c - 将提交推送到 GitHub
- python - Python Pandas:删除A列第一个空单元格下方的所有数据行
- c# - 单击电子邮件中的链接时显示特定记录
- sql - 从带有标签 a 或 b 和 c 的表中选择行
- javascript - 如何在 json/csv 中转换 sql 转储文件
- alfresco - 来自户外内容的常见元数据字段如何工作?
- kubernetes - 在 Kubernetes 集群上使用 etcdctl 时出错:“证书由未知权限签名”