[英]Problem with Broadcast Dispatcher .resume() function Discord JS v12
我正在編寫 Discord JS v12 中的音樂機器人,目前正在處理.pause 和,resume 命令。 它們非常簡單:代碼沒有錯誤。 這就是發生的事情:
歌曲正在播放。
.pause 調用和歌曲暫停,並顯示暫停確認消息。
.resume 調用並顯示恢復確認消息。
歌曲不恢復,其他一切正常,排隊。 !play 命令也是如此。
這是我的!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"
}
這是我的!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"
}
我注意到的是,如果我修改resume命令並刪除最后一個 if 語句,檢查歌曲是否已經暫停,如果我還在 the.resume() 和另一個 extra.resume() 之前添加 a.pause() 和按照相同的步驟,它的工作原理:
這是修改后的 !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"
}
我知道這有點奇怪,也沒有看到太多關於它的信息,但我見過很多人有同樣的錯誤。 我檢查了fetched ,它很好,所以我不知道問題是什么。 伙計們,我將 110% 感謝您的幫助。
我也有這個問題,可以通過使用 Node.js (14.15.5) 的 LTS 版本來解決
對於所有尋找解決方案的人。 dispacter.resume() 在節點 v14.16.1+ 中有錯誤,所以如果你想讓它工作,請使用節點 <=14.16.1。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.