我只能找到该版本的python版本,但是我想要的机器人所要做的就是在完成输入后加入语音通道,例如“%play”并播放mp3文件。
谢谢
答案 0 :(得分:2)
首先,JackRed所说的是正确的,关于您想做的事情有很多信息。 在您提出要求之前,请先在Google上进行搜索,然后可以找到很多教程和指南。
如果问题是使漫游器加入语音通道,请查看here文档或this。请注意,您必须拥有discord.js 12或更高版本才能使用语音
您想要的是这样的:
client.on('message', async message => {
if (message.content === '%play') {
// Join the same voice channel of the author of the message
if (message.member.voice.channel) {
const connection = await message.member.voice.channel.join();
// Play audio, see below
}
}
});
要播放文件,请查看discord.js指南here,因为它很简单,它告诉您需要了解的所有信息,或更具体地说,here就是您想要的。 想要的就是这样
// when in the voice channel
// Create a dispatcher
const dispatcher = connection.play('audio.mp3');
dispatcher.on('start', () => {
console.log('audio.mp3 is now playing!');
});
dispatcher.on('finish', () => {
console.log('audio.mp3 has finished playing!');
});
// Always remember to handle errors
dispatcher.on('error', console.error);```