naatthhaan
naatthhaan
DIAdiscord.js - Imagine an app
Created by naatthhaan on 10/13/2024 in #djs-questions
Get user who deleted a message
cool. thank you for the help
8 replies
DIAdiscord.js - Imagine an app
Created by naatthhaan on 10/13/2024 in #djs-questions
Get user who deleted a message
is it just better for api calls?
8 replies
DIAdiscord.js - Imagine an app
Created by naatthhaan on 10/13/2024 in #djs-questions
Get user who deleted a message
ah I see
8 replies
DIAdiscord.js - Imagine an app
Created by naatthhaan on 8/22/2024 in #djs-voice
Trying to record VC but the out file is static
module.exports = {
data: new SlashCommandBuilder()
.setName('record')
.setDescription('Record voice channel')
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator),

async execute(interaction, client) {
const voiceChannel = interaction.member.voice.channel;
if (!voiceChannel) {
return interaction.reply('You need to be in a voice channel to use this command.');
}

const connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
});

let outputStream;

connection.on(VoiceConnectionStatus.Ready, () => {
console.log(`Connected to channel ${voiceChannel.id}`);
outputStream = startRecording(connection);
});

connection.on(VoiceConnectionStatus.Disconnected, () => {
console.log('Bot disconnected from the voice channel.');

if (fs.existsSync(recordingFilePath)) {
console.log(`Finalizing recording at ${recordingFilePath}`);
outputStream.end(); // Close the file stream
}
});

connection.on(VoiceConnectionStatus.Destroyed, () => {
console.log('Voice connection was destroyed.');
if (fs.existsSync(recordingFilePath)) {
fs.unlinkSync(recordingFilePath);
}
});
}
};
module.exports = {
data: new SlashCommandBuilder()
.setName('record')
.setDescription('Record voice channel')
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator),

async execute(interaction, client) {
const voiceChannel = interaction.member.voice.channel;
if (!voiceChannel) {
return interaction.reply('You need to be in a voice channel to use this command.');
}

const connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
});

let outputStream;

connection.on(VoiceConnectionStatus.Ready, () => {
console.log(`Connected to channel ${voiceChannel.id}`);
outputStream = startRecording(connection);
});

connection.on(VoiceConnectionStatus.Disconnected, () => {
console.log('Bot disconnected from the voice channel.');

if (fs.existsSync(recordingFilePath)) {
console.log(`Finalizing recording at ${recordingFilePath}`);
outputStream.end(); // Close the file stream
}
});

connection.on(VoiceConnectionStatus.Destroyed, () => {
console.log('Voice connection was destroyed.');
if (fs.existsSync(recordingFilePath)) {
fs.unlinkSync(recordingFilePath);
}
});
}
};
7 replies
DIAdiscord.js - Imagine an app
Created by naatthhaan on 8/22/2024 in #djs-voice
Trying to record VC but the out file is static
const { SlashCommandBuilder, PermissionsBitField } = require('discord.js');
const { joinVoiceChannel, VoiceConnectionStatus, EndBehaviorType } = require('@discordjs/voice');
const fs = require('fs');
const path = require('path');

const recordingFilePath = path.join(__dirname, 'recording.pcm');

const startRecording = (connection) => {
console.log(`Recording audio to ${recordingFilePath}`);

const outputStream = fs.createWriteStream(recordingFilePath, { flags: 'w' });

connection.receiver.speaking.on('start', (userId) => {
console.log(`User ${userId} started speaking.`);

const audioStream = connection.receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 1000,
},
});

audioStream.on('data', (chunk) => {
console.log(`Received ${chunk.length} bytes from user ${userId}`);
outputStream.write(chunk);
});

audioStream.on('end', () => {
console.log(`Audio stream ended for user ${userId}`);
});

audioStream.on('error', (err) => {
console.error('Stream error:', err);
});
});

return outputStream;
};
const { SlashCommandBuilder, PermissionsBitField } = require('discord.js');
const { joinVoiceChannel, VoiceConnectionStatus, EndBehaviorType } = require('@discordjs/voice');
const fs = require('fs');
const path = require('path');

const recordingFilePath = path.join(__dirname, 'recording.pcm');

const startRecording = (connection) => {
console.log(`Recording audio to ${recordingFilePath}`);

const outputStream = fs.createWriteStream(recordingFilePath, { flags: 'w' });

connection.receiver.speaking.on('start', (userId) => {
console.log(`User ${userId} started speaking.`);

const audioStream = connection.receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 1000,
},
});

audioStream.on('data', (chunk) => {
console.log(`Received ${chunk.length} bytes from user ${userId}`);
outputStream.write(chunk);
});

audioStream.on('end', () => {
console.log(`Audio stream ended for user ${userId}`);
});

audioStream.on('error', (err) => {
console.error('Stream error:', err);
});
});

return outputStream;
};
7 replies