简体   繁体   English

Broadcast Dispatcher.resume() 的问题 function Discord JS v12

[英]Problem with Broadcast Dispatcher .resume() function Discord JS v12

I am coding a music bot in Discord JS v12 and am currently working on the.pause and,resume commands.我正在编写 Discord JS v12 中的音乐机器人,目前正在处理.pause 和,resume 命令。 They're quite simple: and the code has no errors.它们非常简单:代码没有错误。 This is what happens:这就是发生的事情:

  1. Song is playing.歌曲正在播放。

  2. .pause invoked and song pause and the pause confirmationn message is displayed. .pause 调用和歌曲暂停,并显示暂停确认消息。

  3. .resume invoked and the resume confirmation message is displayed. .resume 调用并显示恢复确认消息。

  4. Song does not resume, everything else works perfectly, ,queue.歌曲不恢复,其他一切正常,排队。 !play commands as well. !play 命令也是如此。

    This is my !pause command code:这是我的!pause命令代码:

// Discord.js initialization.
const Discord = require("discord.js");

// Functions initialization.
const functions = require("../../functions.js");

// Initialization of the server specific variables data.
const serverData = require("../../serverData.json");

// The command's code goes inside an async function.
module.exports.run = async (bot, message, args, ops) => {

    /****************************/
    /****  MESSAGE DELETION  ****/
    /****************************/

    // Deletes the command invocation.
    await message.delete().catch(O_o => { });

    /************************/
    /****  CONDITIONALS  ****/
    /************************/

    // Fetches the guild object from the Map.
    let fetched = ops.active.get(message.guild.id);

    // Checks if there is any object in the fetched.
    if (!fetched) {

        // End of the function and message prints
        return message.channel.send(`> ${message.author}, there is no music playing or queued.`).then(msg => msg.delete({ timeout: 3000 }));
    }

    // Checks if the message author is in the same voice channel as the bot.
    if (message.member.voice.channel !== message.guild.me.voice.channel) {

        // End of the function and message prints.
        return message.channel.send(`> ${message.author}, you must be in the same voice channel as the bot.`).then(msg => msg.delete({ timeout: 3000 }));
    }

    // Then, check if the dispatcher is already paused.
    if(fetched.dispatcher.paused){

        // End of the function and message prints.
        return message.channel.send(`> ${message.author}, the song is already paused.`).then(msg => msg.delete({ timeout: 3000 }));
    }

    /*****************************/
    /****  COMMAND EXECUTION  ****/
    /*****************************/

    // If nothing made the command exit, it executes the pause.
    fetched.dispatcher.pause(true);

    // Otherwise tell them in chat that they added a vote to skip.
    message.channel.send(`> ${message.member}, the current song has been paused.`).then(msg => msg.delete({ timeout: 4000 }));
}

// Command name.
module.exports.help = {
    name: "pause"
}

This is my !resume command code:这是我的!resume命令代码:

// Discord.js initialization.
const Discord = require("discord.js");

// Functions initialization.
const functions = require("../../functions.js");

// Initialization of the server specific variables data.
const serverData = require("../../serverData.json");

// The command's code goes inside an async function.
module.exports.run = async (bot, message, args, ops) => {

    /****************************/
    /****  MESSAGE DELETION  ****/
    /****************************/

    // Deletes the command invocation.
    await message.delete().catch(O_o => { });

    /************************/
    /****  CONDITIONALS  ****/
    /************************/

    // Fetches the guild object from the Map.
    let fetched = ops.active.get(message.guild.id);

    // Checks if there is any object in the fetched.
    if (!fetched) {

        // End of the function and message prints
        return message.channel.send(`> ${message.author}, there is no music playing or queued.`).then(msg => msg.delete({ timeout: 3000 }));
    }

    // Checks if the message author is in the same voice channel as the bot.
    if (message.member.voice.channel !== message.guild.me.voice.channel) {

        // End of the function and message prints.
        return message.channel.send(`> ${message.author}, you must be in the same voice channel as the bot.`).then(msg => msg.delete({ timeout: 3000 }));
    }

    // Then, check if the dispatcher is already paused.
    if(!fetched.dispatcher.paused){

        // End of the function and message prints.
        return message.channel.send(`> ${message.author}, the song is not paused.`).then(msg => msg.delete({ timeout: 3000 }));
    }

    /*****************************/
    /****  COMMAND EXECUTION  ****/
    /*****************************/

    // If nothing made the command exit, it executes the pause.
    fetched.dispatcher.resume(true);

    // Otherwise tell them in chat that they added a vote to skip.
    message.channel.send(`> ${message.member}, the current song has been resumed.`).then(msg => msg.delete({ timeout: 4000 }));
}

// Command name.
module.exports.help = {
    name: "resume"
}

What I have noticed is that if I modify the resume command and remove the last if sentence checking if the song is already paused, and if I also add a.pause() before the.resume() and another extra.resume() and follow the same steps, it works:我注意到的是,如果我修改resume命令并删除最后一个 if 语句,检查歌曲是否已经暂停,如果我还在 the.resume() 和另一个 extra.resume() 之前添加 a.pause() 和按照相同的步骤,它的工作原理:

  1. Song is playing.歌曲正在播放。
  2. .pause invoked and song pause and the pause confirmationn message is displayed. .pause 调用和歌曲暂停,并显示暂停确认消息。
  3. .resume invoked and the resume confirmation message is displayed. .resume 调用并显示恢复确认消息。
  4. ,resume invoked a second time and the song resumes with barely any sound glitches. ,resume 再次调用,歌曲继续播放,几乎没有任何声音故障。 also sends a resume confirmation message on the chat.还会在聊天中发送简历确认消息。
  5. .pause invoked and song pauses and sends the pause confirmation message. .pause 被调用,歌曲暂停并发送暂停确认消息。
  6. ,resume invoked only one time and the song resumes with barely any sound glitches. ,resume 只调用了一次,歌曲继续播放,几乎没有任何声音故障。 also sends a resume confirmation message on the chat.还会在聊天中发送简历确认消息。
  7. From now on the commands work okay.从现在开始,命令可以正常工作。

This is the modified !resume command code:这是修改后的 !resume命令代码:

// Discord.js initialization.
const Discord = require("discord.js");

// Functions initialization.
const functions = require("../../functions.js");

// Initialization of the server specific variables data.
const serverData = require("../../serverData.json");

// The command's code goes inside an async function.
module.exports.run = async (bot, message, args, ops) => {

    /****************************/
    /****  MESSAGE DELETION  ****/
    /****************************/

    // Deletes the command invocation.
    await message.delete().catch(O_o => { });

    /************************/
    /****  CONDITIONALS  ****/
    /************************/

    // Fetches the guild object from the Map.
    let fetched = ops.active.get(message.guild.id);

    // Checks if there is any object in the fetched.
    if (!fetched) {

        // End of the function and message prints
        return message.channel.send(`> ${message.author}, there is no music playing or queued.`).then(msg => msg.delete({ timeout: 3000 }));
    }

    // Checks if the message author is in the same voice channel as the bot.
    if (message.member.voice.channel !== message.guild.me.voice.channel) {

        // End of the function and message prints.
        return message.channel.send(`> ${message.author}, you must be in the same voice channel as the bot.`).then(msg => msg.delete({ timeout: 3000 }));
    }

    /*****************************/
    /****  COMMAND EXECUTION  ****/
    /*****************************/

    // If nothing made the command exit, it executes the pause.
    fetched.dispatcher.pause(true);
    fetched.dispatcher.resume();
    fetched.dispatcher.resume();
    

    // Otherwise tell them in chat that they added a vote to skip.
    message.channel.send(`> ${message.member}, the current song has been resumed.`).then(msg => msg.delete({ timeout: 4000 }));
}

// Command name.
module.exports.help = {
    name: "resume"
}

I know this is a bit weird and haven't seen much info on it but I have seen many people that have the same error.我知道这有点奇怪,也没有看到太多关于它的信息,但我见过很多人有同样的错误。 I checked fetched and it's good, so I don't know what the problem is.我检查了fetched ,它很好,所以我不知道问题是什么。 I would 110% appreciate your help here, guys.伙计们,我将 110% 感谢您的帮助。

I had this problem too, it can be fixed by using the LTS version of Node.js (14.15.5)我也有这个问题,可以通过使用 Node.js (14.15.5) 的 LTS 版本来解决

For everyone looking for solution.对于所有寻找解决方案的人。 dispacter.resume() is buggy in node v14.16.1+ So if you want it to work use node <=14.16.1. dispacter.resume() 在节点 v14.16.1+ 中有错误,所以如果你想让它工作,请使用节点 <=14.16.1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM