如何停止播放机器人音乐?(Discord.js)
这段代码是用来播放音乐的,我想在我的机器人上有一个停止命令。你能帮我吗如何停止播放机器人音乐?(Discord.js),discord,bots,discord.js,Discord,Bots,Discord.js,这段代码是用来播放音乐的,我想在我的机器人上有一个停止命令。你能帮我吗 const Discord = require("discord.js"); const client = new Discord.Client(); const config = require("./config.json") const ytdl = require("ytdl-core") const streamOptions = {seek:0, vol
const Discord = require("discord.js");
const client = new Discord.Client();
const config = require("./config.json")
const ytdl = require("ytdl-core")
const streamOptions = {seek:0, volume:1}
client.on("message", async message => {
if(message.author.bot) return
if(message.channel.type === "dm") return
if(!message.content.startsWith(config.prefix)) return
const args = message.content.slice(config.prefix.length).trim().split(/ +/g)
const comando = args.shift().toLocaleLowerCase()
if(comando === "play") {
var voiceChannel = message.guild.channels.cache.get("733122593019789314")
let file = args[0]
if(voiceChannel == null) {
console.log("Canal não encontrado.")
}
if(voiceChannel != null) {
console.log("Canal encontrado.")
await voiceChannel.join().then(connection => {
const stream = ytdl(file, {filter:"audioonly", quality:"highestaudio"})
const DJ = connection.play(stream, streamOptions)
DJ.on("end", end => {
voiceChannel.leave()
})
}).catch(console.error)
}
}/* I was trying to do the command this way:
else if(comando === "stop") {
voiceChannel.leave()
}*/
}
client.login(config.token);
一切正常,我只想停止音乐
(我是巴西人,有些单词或句子可能是错的。)
谢谢你的帮助 你可以使用。()和。()
您的定义为DJ
,因此您可以使用:
DJ.pause();//暂停溪流。
DJ.resume();//恢复流。
DJ.destroy();//小溪的尽头。
好的,我尝试这样做,但返回一个错误,说“DJ未定义”。我试图将“const”改为“var”,但它不起作用,并将const DJ=connection.play(stream,streamOptions)
更改为DJ=connection.play(stream,streamOptions)
。它不起作用。我更改了代码,但它仍然给我一个错误。。。谢谢你的帮助。我要去discord.js文档寻找答案。我刚想用voiceChacnnel.leave()。我试试看,然后告诉你。它成功了!!!!我只是验证命令是play还是stop。如果是stop,则此代码将运行:等待voiceChannel.leave()
非常简单。非常感谢。