© 2026 Hedgehog Software, LLC
const { Client, GatewayIntentBits, Partials, } = require('discord.js'); const { joinVoiceChannel, EndBehaviorType } = require('@discordjs/voice'); const fs = require('node:fs'); const stream = require('node:stream'); const client = new Client({ intents: Object.values(GatewayIntentBits), partials: [Partials.Message, Partials.Channel, Partials.Reaction], rest: 60000 }); const prefix = '!'; client.once('ready', () => { console.log(`Logged in as ${client.user.tag}`); }); client.on('messageCreate', async (message) => { if (message.content.startsWith(prefix + 'join')) { const voiceChannel = message.member?.voice.channel; if (!voiceChannel) { return message.reply('このコマンドを使用するには、音声チャンネルに参加している必要があります。'); } const connection = joinVoiceChannel({ channelId: voiceChannel.id, guildId: voiceChannel.guild.id, adapterCreator: voiceChannel.guild.voiceAdapterCreator, }); connection.receiver.speaking.on('start', (userId) => { const audio = connection.receiver.subscribe(userId, { end: { behavior: EndBehaviorType.AfterSilence, duration: 100, }, }); var filename = './rec/'.concat(Date.now(), '-').concat(userId, '.pcm'); var out = fs.createWriteStream(filename); stream.pipeline(audio, out, function (err) { if (err) { console.warn(`❌ Error recording file ${filename} - ${err.message}`); } else { console.log(`✅ Recorded ${filename}`); } }); }); } });
Join the Discord to ask follow-up questions and connect with the community
Support server for discord.js, a Node.js module to interact with Discord's apps API.
57,666 Members