我是Discord.js的新手,我正在尝试让该漫游器加入语音通道并在计算机上播放音频文件。我一直在遵循本指南:https://discord.js.org/#/docs/main/stable/topics/voice。这是Index.js页面:
const Discord = require('discord.js');
const Colesbot = new Discord.Client();
const token = 'NjY4OTcyNDA4NTc2ODAyODQw.Xk4VWg.opGZhMXv_w2iJFuQCIGBr_VsQj0';
Colesbot.on('ready', () =>{
console.log('Slamsbot is online.');
})
Colesbot.on('message', msg=>{
if(msg.content == "What up bot?"){
msg.reply("Whats good pimp?")
}
});
Colesbot.on('message', message=>{
if (message.content === '/join') {
// Only try to join the sender's voice channel if they are in one themselves
if (message.member.voiceChannel) {
message.member.voiceChannel.join().then(connection => {
message.reply('I have successfully connected to the channel!');
// To play a file, we need to give an absolute path to it
const dispatcher = connection.playFile('C:\Users\bobal\Documents\GitHub\Spotify-Playlist-Discord-bot\Assets\Glory.mp3');
dispatcher.on('end', () => {
// The song has finished
console.log('Finished playing!');
});
dispatcher.on('error', e => {
// Catch any errors that may arise
console.log(e);
});
dispatcher.setVolume(0.5); // Set the volume to 50%
}).catch(console.log);
} else {
message.reply('You need to join a voice channel first!');
}
}
});
//Event listener for new guild members
Colesbot.on('guildMemberAdd', member =>{
// Send the message to a designated channel on a server:
const channel = member.guild.channels.find(ch => ch.name === 'general');
// Do nothing if the channel wasn't found on this server
if (!channel) return;
// Send the message, mentioning the member
channel.send(`Welcome to the server, ${member}. Please use the bot-commands channel to assign yourself a role.`);
})
Colesbot.login(token);
exports.run = (client, message, args) => {
let user = message.mentions.users.first || message.author;
}
我没有任何错误,音乐无法播放。当我键入/ join时,机器人会加入语音通道,但这只是沉默。如果您需要任何其他信息,我将很乐意提供。我觉得我缺少必要的组件,但我不知道它是什么。
首先,您需要重置令牌,永远不要在线发布令牌,因为其他人可以使用它来访问和控制您的机器人
我认为您需要安装FFMPEG并为其设置环境路径,但是,您可以提供更多信息,控制台日志,行为等吗?>