【发布时间】:2021-12-08 11:23:34
【问题描述】:
我打算为我的 discord 机器人添加一些语音功能,但由于某种原因,当我运行我的代码时,它没有发出声音 而 discord 确实在我的机器人周围显示了绿色圆圈,表明它正在制作声音。它也不会记录任何错误或其他任何内容,有人知道我的代码有什么问题吗?
代码:
if (command == "soundtest") {
mongo().then(async (mongoose) => {
const { voice } = msg.member
if (voice.channelID) {
const vc = voice.channel
// console.log(channel)
try {
vc.join().then(connection => {
connection.play(path.join(__dirname, 'Bastille_Pompeii.mp3'))
})
} catch(e) {
console.log("error")
console.log(e)
}
} else {
msg.channel.send(`You must join a voice channel to use this command`)
}
})
}
感谢阅读!
【问题讨论】:
-
这能回答你的问题吗? Play local music files using djs v13
-
@MegaMix_Craft OP 似乎正在使用 v12,您可以通过他们加入
VoiceChannel.join来判断这一点 -
@MegaMix_Craft 我试过了,但没有用,将代码中的行更改为 `connection.play(path.join('..', 'musicfiles', 'Bastille_Pompeii.mp3' ))`,因为该文件称为 Bastille_Pompeii.mp3 并且位于我所在脚本的父文件夹内的文件夹“musicfiles”中
-
@MrMythical 我正在使用 discord.js v13
-
@MrMythical 我不知道什么时候做的,但它对我有用,所以显然它没有被删除?
标签: javascript node.js ffmpeg discord discord.js