This commit is contained in:
Flatlogic Bot 2026-02-16 08:01:11 +00:00
parent f2d5361ba4
commit da32ad26c6
2 changed files with 53 additions and 1600 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,4 @@
const { Client, GatewayIntentBits, Events, EmbedBuilder, PermissionsBitField } = require('discord.js');
const {
joinVoiceChannel,
createAudioPlayer,
createAudioResource,
AudioPlayerStatus,
StreamType,
VoiceConnectionStatus
} = require('@discordjs/voice');
const { DisTube } = require('distube');
const { YtDlpPlugin } = require('@distube/yt-dlp');
const { SoundCloudPlugin } = require('@distube/soundcloud');
@ -26,18 +18,13 @@ if (!process.env.PATH.includes(ffmpegDir)) {
process.env.PATH = `${ffmpegDir}${path.delimiter}${process.env.PATH}`;
}
// Generate dependency report for debugging
try {
const { generateDependencyReport } = require('@discordjs/voice');
console.log("Dependency Report:\n" + generateDependencyReport());
} catch (e) {}
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers // Added to fetch members for alarm
]
});
@ -75,37 +62,6 @@ function logToFile(message) {
console.log(message);
}
async function playLocalFile(voiceChannel) {
const connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator,
selfDeaf: false,
selfMute: false,
});
const player = createAudioPlayer();
player.on('error', error => {
logToFile(`Audio Player Error: ${error.message}`);
});
const resource = createAudioResource(AUDIO_PATH, {
inputType: StreamType.Arbitrary,
inlineVolume: true,
});
resource.volume.setVolume(1.0);
player.play(resource);
connection.subscribe(player);
player.on(AudioPlayerStatus.Idle, () => {
// connection.destroy();
});
return connection;
}
client.once(Events.ClientReady, () => {
logToFile(`Bot berhasil login!`);
logToFile(`Ready! Logged in as ${client.user.tag}`);
@ -130,27 +86,16 @@ client.once(Events.ClientReady, () => {
const channel = guild.channels.cache.get(VC_ID);
if (channel && fs.existsSync(AUDIO_PATH)) {
try {
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: guild.id,
adapterCreator: guild.voiceAdapterCreator,
selfDeaf: false,
selfMute: false,
// Use DisTube to play alarm
await distube.voices.join(channel, { selfDeaf: false, selfMute: false });
await distube.play(channel, AUDIO_PATH, {
textChannel: guild.systemChannel || undefined,
skip: true,
member: guild.members.me || undefined
});
const player = createAudioPlayer();
const resource = createAudioResource(AUDIO_PATH, {
inputType: StreamType.Arbitrary,
inlineVolume: true,
});
resource.volume.setVolume(1.0);
player.play(resource);
connection.subscribe(player);
logToFile('Alarm playing with custom audio resource.');
logToFile('Alarm playing via DisTube.');
} catch (err) {
logToFile(`Alarm join error: ${err.message}`);
logToFile(`Alarm play error: ${err.message}`);
}
}
}, null, true, 'Asia/Jakarta');
@ -171,13 +116,7 @@ client.on(Events.InteractionCreate, async interaction => {
if (commandName === 'join') {
if (!voiceChannel) return interaction.reply({ content: 'Anda harus berada di voice channel!', ephemeral: true });
await interaction.deferReply();
joinVoiceChannel({
channelId: voiceChannel.id,
guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator,
selfDeaf: false,
selfMute: false,
});
await distube.voices.join(voiceChannel, { selfDeaf: false, selfMute: false });
await interaction.editReply('Sudah join! 🎧');
}
@ -186,9 +125,15 @@ client.on(Events.InteractionCreate, async interaction => {
if (!fs.existsSync(AUDIO_PATH)) return interaction.reply({ content: `File audio tidak ditemukan di ${AUDIO_PATH}`, ephemeral: true });
await interaction.deferReply();
logToFile(`Playing local file using custom resource: ${AUDIO_PATH}`);
logToFile(`Playing local file via DisTube: ${AUDIO_PATH}`);
try {
await playLocalFile(voiceChannel);
await distube.voices.join(voiceChannel, { selfDeaf: false, selfMute: false });
await distube.play(voiceChannel, AUDIO_PATH, {
member: interaction.member,
textChannel: interaction.channel,
interaction,
skip: true
});
await interaction.editReply('Memainkan suara sahur... 📢');
} catch (e) {
logToFile(`Error in testsahur: ${e.message}`);
@ -201,26 +146,20 @@ client.on(Events.InteractionCreate, async interaction => {
if (!voiceChannel) return interaction.reply({ content: 'Anda harus berada di voice channel!', ephemeral: true });
await interaction.deferReply();
logToFile(`Fetching stream for: ${query}`);
logToFile(`Fetching stream via DisTube for: ${query}`);
// Ensure connection with specific settings
joinVoiceChannel({
channelId: voiceChannel.id,
guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator,
selfDeaf: false,
selfMute: false,
});
distube.play(voiceChannel, query, {
member: interaction.member,
textChannel: interaction.channel,
interaction
}).catch(e => {
try {
await distube.voices.join(voiceChannel, { selfDeaf: false, selfMute: false });
await distube.play(voiceChannel, query, {
member: interaction.member,
textChannel: interaction.channel,
interaction
});
await interaction.editReply(`Mencari: **${query}**... 🔍`);
} catch (e) {
logToFile(`Play Error: ${e.message}`);
interaction.editReply(`Terjadi kesalahan saat memutar: ${e.message}`);
});
await interaction.editReply(`Mencari: **${query}**... 🔍`);
}
}
else if (commandName === 'pause') {
@ -266,15 +205,8 @@ client.on(Events.MessageCreate, async message => {
if (!voiceChannel) return message.reply('Anda harus berada di voice channel!');
if (!query) return message.reply('Masukkan judul atau link lagu!');
joinVoiceChannel({
channelId: voiceChannel.id,
guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator,
selfDeaf: false,
selfMute: false,
});
distube.play(voiceChannel, query, {
await distube.voices.join(voiceChannel, { selfDeaf: false, selfMute: false });
await distube.play(voiceChannel, query, {
member: message.member,
textChannel: message.channel,
message
@ -287,7 +219,13 @@ client.on(Events.MessageCreate, async message => {
} else if (command === 'testsahur') {
if (!voiceChannel) return message.reply('Anda harus berada di voice channel!');
try {
await playLocalFile(voiceChannel);
await distube.voices.join(voiceChannel, { selfDeaf: false, selfMute: false });
await distube.play(voiceChannel, AUDIO_PATH, {
member: message.member,
textChannel: message.channel,
message,
skip: true
});
message.reply('Mengetes suara sahur... 📢');
} catch (e) {
message.reply(`❌ Error: ${e.message}`);