【发布时间】:2021-10-02 10:53:38
【问题描述】:
所以我对 play.js 命令的 main.js 文件有问题。
当我检查控制台时,它说问题就在这里:
client.commands.get('play').execute(message, args);
^
这里是 play.js 命令:
const ytdl = require("ytdl-core");
const ytSearch = require("yt-search");
module.exports = {
name: "play",
description: "Play Komanda",
async execute(message, args) {
const voiceChannel = message.member.voice.channel;
if (!voiceChannel) return message.channel.send("Moraš biti u nekom kanalu kako bi koristio ovu komandu!");
const permissions = voiceChannel.permissionsFor(message.client.user);
if (!permissions.has("CONNECT")) return message.channel.send("Nemaš permisije!");
if (!permissions.has("SPEAK")) return message.channel.send("Nemaš permisiju!");
if (!args.length) return message.channel.send("Moraš poslati drugi argumenat.");
const validURL = (str) => {
var regex = /(http|https):\/\/(\w+:{0,1}\w*)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%!\-\/]))?/;
if (!regex.test(str)) {
return false;
} else {
return true;
}
};
if (validURL(args[0])) {
const connection = await voiceChannel.join();
const stream = ytdl(args[0], { filter: "audioonly" });
connection.play(stream, { seek: 0, volume: 1 }).on("finish", () => {
voiceChannel.leave();
message.channel.send("leaving channel");
});
await message.reply(`:musical_note: Trenutno slušaš ***Your Link!***`);
return;
}
const connection = await voiceChannel.join();
const videoFinder = async (query) => {
const videoResult = await ytSearch(query);
return videoResult.videos.length > 1 ? videoResult.videos[0] : null;
};
const video = await videoFinder(args.join(" "));
if (video) {
const stream = ytdl(video.url, { filter: "audioonly" });
connection.play(stream, { seek: 0, volume: 1 }).on("finish", () => {
voiceChannel.leave();
});
await message.reply(`:musical_note: Trenutno slušaš ***${video.title}***`);
} else {
message.channel.send("Nijedan video nije pronadjen");
}
},
};
【问题讨论】:
-
你能记录这个吗:
console.log(client.commands.get('play'))并检查它是否为空/未定义 -
另外,你能告诉我们你设置所有命令的代码吗?
-
@Toasty 它说它是未定义的
-
你还在设置你的命令吗?就像在您的
index.js或命令处理程序中一样? -
@Toasty 如果你的意思是这样(prnt.sc/1g66ofj)是的。
标签: javascript node.js discord.js