创建音乐模块时,我在制作Discord机器人时遇到了一些问题。它使用ytdl-core
和ffmpeg
这是有问题的一行:
if server.dispatcher server.dispatcher.end();
我收到以下错误:
无法阅读财产"调度员"未定义的。
有人能帮助我吗?
// Constants, variables and functions
const ffmpeg = require('ffmpeg')
const Discord = require('discord.js');
const client = new Discord.Client();
const YTDL = require('ytdl-core');
const clientprefix = "//";
const opusscript = require('opusscript');
const moderatorprefix = "> ";
// Functions and variables
var errorEmbedCreate = function(des) {
return({embed: {color: 16711680, title: ":x: Error",description: des}});
}
var warningEmbedCreate = function(des) {
return({embed: {color: 16763904, title: ":warning: Warning",description: des}});
}
var embedCreate = function(col,des,tit) {
return({embed: {color: col, title: tit,description: des}});
}
var cat = "http://random.cat/meow.php"
var servers = [];
function play(connection, message) {
var server = servers[message.guild.id];
server.dispatcher = connection.playStream(YTDL(server.queue[0], {filter:"audioonly"}));
server.queue.shift();
server.dispatcher.on("end", function() {
if (server.queue[0]) play(connection, message);
else connection.disconnect();
});
}
每次执行命令时都会创建:
var server = servers[message.guild.id];