javascript - 如何使用 Discord.js 在我的音乐机器人上添加队列?
问题描述
这是我的音乐机器人的播放命令
module.exports = {
name: 'p',
description: 'Joins and plays a video from youtube',
async execute(message, args) {
const voiceChannel = message.member.voice.channel;
if (!voiceChannel) return message.channel.send('You need to be in a channel to execute this command!');
const permissions = voiceChannel.permissionsFor(message.client.user);
if (!permissions.has('CONNECT')) return message.channel.send('You dont have the correct permissins');
if (!permissions.has('SPEAK')) return message.channel.send('You dont have the correct permissins');
if (!args.length) return message.channel.send('You need to send the second argument!');
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(`:thumbsup: Now Playing ***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(`:thumbsup: Now Playing ***${video.title}***`)
} else {
message.channel.send('No video results found');
}
}
}
这是做什么的,!p *name of the song/link*
然后他加入并播放,但我不能做两首歌。比第一次完成时,第二次播放。
我想添加队列系统和跳过命令。你能帮我添加一个队列和跳过系统吗?
解决方案
推荐阅读
- c# - 如何在 C# 中使用 BouncyCastle 创建具有到期和/或名称的 RSA 密钥?
- unix - unix shell 中 2 个别名 cd 之间的行为差异
- angularjs - Angular 组件被忽略
- xcode - 无法在 macOS Big Sur 11.4 上启动 Xcode 13 beta 1 和/或 2
- oauth-2.0 - Auth0 React JS 快速入门不请求所有范围
- java - Spring Boot:使用 Rest 模板管理多个端点?
- c - 从用户而不是标准输入读取输入
- python - 如何在 databricks DRE 7.6 及更高版本上使用 python3/python2 mypthon3.zip 编译的 zip 执行 spark 提交作业?
- javascript - Next-Image 相对路径有效,但在抓取时指向 404 页面
- vue.js - 当我更改语言时,VuePress 更改主题