如果您想让您的 DiscordJS 机器人加入成员的语音频道,您可以使用 join()
方法。您需要传递声道的 ID 或 VoiceChannel 对象。如果您想让机器人加入请求消息的成员当前所在的语音频道,可以使用 member.voice.channel
属性。
以下是一个示例代码,演示了如何在 Discord 服务器中使用 DiscordJS 加入成员的语音频道。
client.on('message', async (message) => {
if (message.content === '!join') {
if (message.member.voice.channel) {
const connection = await message.member.voice.channel.join();
console.log(`Joined ${connection.channel.name}`);
} else {
message.reply('You need to join a voice channel first!');
}
}
});
下一篇:不加入Rust线程有什么缺点?