命令处理程序中的Discord.js Music Bot [英] Discord.js Music Bot in a command handler

查看:92
本文介绍了命令处理程序中的Discord.js Music Bot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在命令处理程序中制作一个音乐机器人,但是遇到了一些问题。
这是我使用的命令处理程序:

I want to make a music bot in my command handler, but I ran into some problems. This is the command handler I use:

delete require.cache[require.resolve(`./commands/${command}.js`)];

let commandFile = require(`./commands/${command}.js`);
commandFile.run(client, message, args);

在我的play.js文件中,我有一个队列:

And in my play.js file I have a queue:

var servers = {};

我不知道如何制作歌曲以便跳过歌曲(使用skip命令-skip.js)。跳过代码:

I don't know how to make it so that I can skip a song (using the skip command - skip.js) in the queue. Code for skipping:

if (server.dispatcher) server.dispatcher.end();

我尝试查看教程,但是它们都在一个文件中完成,因此更加容易,因为您可以把 var服务器= {};在顶部,并且可以正常工作。我找不到任何教程来展示如何制作它,以便可以使用像我这样的命令处理程序。

I tried looking at tutorials but they all do it in one file wich makes it easier because you can just put the "var servers = {};" on the top and its going to work. I couldn't find any tutorials where they shown how to make it so that you can use a command handler like mine.

这里是所有文件:

play.js- https://hastebin.com/dijavugufu.js

skip.js- https:/ /hastebin.com/kupecayotu.js

如果有人告诉我如何修改其他音乐机器人命令以与命令处理程序一起使用,这也很好。 。

It would also be nice if someone told me how to modify some other music bot commands to work with a command handler.

推荐答案

嘿,伙计,不确定您是否仍在寻找答案,但我还在与命令处理程序。我解决这个问题的方法是直接从播放文件中导出跳过功能,并在跳过文件中使用该功能。

Hey man not sure if you're still looking for an answer but I'm also working on a bot with a command handler. The way I got around this was to export the skip function directly from the play file and use that function in the skip file. Here's kinda what I did.

/*In play.js*/
var dispatcher;
async function Play(connection, message){
    dispatcher = await connection.playStream("your url and options here");
}
module.exports.Skip = function(){
    if(dispatcher) dispatcher.end();
}

/*In skip.js*/
const playModule = require("your_path_to/play.js");
module.exports.run = async (client, message, args) => {
    var skip = playModule.Skip();
}

对不起,我对Node.js仍然很陌​​生,并且创建了Discord bot,这可能不是最优雅的解决方案。但是要点是,我通过在play.js中编写函数并将该函数导出到skip.js并在其中调用来解决了这个问题。

Sorry, I'm still pretty new to Node.js and creating a Discord bot and this may not be the most elegant solution. But the main point is that I got around it by writing the function in play.js and exporting that function to skip.js and calling it there.

这篇关于命令处理程序中的Discord.js Music Bot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆