Discord 如何从另一个文件触发命令

Discord 如何从另一个文件触发命令,discord,discord.js,Discord,Discord.js,我正在尝试创建一个音乐机器人,但我对loop命令有一个问题,我想在用户单击播放菜单上的某个react表情符号时触发loop.js,目前,该命令在play.js和loop.js中独立运行。我想这样做的原因是,如果用户选择了反应,然后自己执行命令,机器人会说相反的话,如果它是开的或关的 这是我的loop.js module.exports = { name: "loop", aliases: ['l'], description: "Toggle music

我正在尝试创建一个音乐机器人,但我对loop命令有一个问题,我想在用户单击播放菜单上的某个react表情符号时触发loop.js,目前,该命令在play.js和loop.js中独立运行。我想这样做的原因是,如果用户选择了反应,然后自己执行命令,机器人会说相反的话,如果它是开的或关的

这是我的loop.js

module.exports = {
  name: "loop",
  aliases: ['l'],
  description: "Toggle music loop",
  execute(message) {

    const queue = message.client.queue.get(message.guild.id);
    if (!queue) return message.reply("There is nothing playing.").catch(console.error);
    if (!canModifyQueue(message.member)) return;

    let loopembed = new MessageEmbed()
    .setTitle("Loop settings")
    .setDescription(`Loop is now ${queue.loop ? "**on**" : "**off**"}`)
    .setColor(message.guild.me.displayColor)
    .setFooter(`Action performed by ${message.author.tag}`)

    // toggle from false to true and reverse
    queue.loop = !queue.loop;
    return queue.textChannel
      .send(loopembed)
      .catch(console.error);
  }
};
这是play.js中的循环反应命令


案例“如果我理解正确,您可以在play.js中只需要loop.js,就像在命令处理程序中一样。你是说我应该删除loop.js并将命令移到play.js?不,我假设你有一个类似于官方指南的命令处理程序结构。无论如何,您可以做的是让
constloop=require('./loop.js')
在play.js的顶部(假设loop.js和play.js都在同一个目录中),在切换中断之前,您可以调用loop.js的execute方法作为
loop.execute(message)。进行此更改后,一旦bot对loop作出反应,它将执行loop.js,但随后将停止音乐队列谢谢,我也将尝试找到解决方案