嗨,我一直试图让一个不和谐的机器人加入语音通道已有一段时间,并且一直在挣扎,这是我到目前为止的代码,当我在一般情况下键入“ / join”时会收到此消息服务器聊天。预先感谢!
const Discord = require('discord.js');
const client = new Discord.Client();
client.login('my token);
client.on('message', async message => {
// Voice only works in guilds, if the message does not come from a guild,
// we ignore it
if (!message.guild) return;
if (message.content === '/join') {
// Only try to join the sender's voice channel if they are in one themselves
if (message.member.voice.channel) {
const connection = await message.member.voice.channel.join();
} else {
message.reply('You need to join a voice channel first!');
}
}
});