Spaces:
Runtime error
Runtime error
Upload 2 files
Browse filesFiles changed (2)
- index.jsAdded+127
- package.jsonAdded+20
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127const { Client, GatewayIntentBits, REST, Routes, SlashCommandBuilder } = require('discord.js');
const { joinVoiceChannel, getVoiceConnection } = require('@discordjs/voice');
const cron = require('node-cron');
const express = require('express'); // Disiapkan untuk keperluan Render nanti
// ========================================================
// KONFIGURASI UTAMA (Gunakan Environment Variable untuk Hosting)
// ========================================================
const TOKEN = process.env.TOKEN || 'MTUwNzA2NjE4MTIzMDY2MTczMg.GbexTD.x_ClW1EFzsiEi87VXa8dFh2xDVl0oISz9dKD0c';
const GUILD_ID = process.env.GUILD_ID || '1507067416272965732';
const CHANNEL_ID = process.env.CHANNEL_ID || '1507067419062173719';
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
]
});
// Daftarkan Slash Command (/join dan /leave)
const commands = [
new SlashCommandBuilder().setName('join').setDescription('Menyuruh bot masuk ke voice room secara otomatis'),
new SlashCommandBuilder().setName('leave').setDescription('Menyuruh bot keluar dari voice room'),
].map(command => command.toJSON());
const rest = new REST({ version: '10' }).setToken(TOKEN);
client.once('ready', async () => {
console.log(`π€ Mantap! Bot ${client.user.tag} sudah aktif.`);
// Daftarkan command ke Discord secara otomatis saat bot menyala
try {
console.log('β³ Sedang mendaftarkan Slash Commands...');
await rest.put(
Routes.applicationCommands(client.user.id),
{ body: commands },
);
console.log('β
Slash Commands berhasil didaftarkan secara Global!');
} catch (error) {
console.error('β Gagal mendaftarkan Slash Commands:', error);
}
// ========================================================
// JADWAL OTOMATIS JAM 6 PAGI (KHUSUS SERVER UTAMA)
// ========================================================
cron.schedule('0 6 * * *', () => {
console.log('β° Jam 06.00 WIB: Bot otomatis masuk ke room utama...');
const guild = client.guilds.cache.get(GUILD_ID);
const channel = guild.channels.cache.get(CHANNEL_ID);
if (channel) {
joinVoiceChannel({
channelId: channel.id,
guildId: guild.id,
adapterCreator: guild.voiceAdapterCreator,
selfMute: false,
selfDeaf: true
});
console.log('β
Bot berhasil standby di room utama.');
}
}, {
timezone: "Asia/Jakarta"
});
// JADWAL OTOMATIS JAM 5 SORE (KHUSUS SERVER UTAMA)
cron.schedule('0 17 * * *', () => {
console.log('β° Jam 17.00 WIB: Waktunya bot keluar dari room utama...');
const connection = getVoiceConnection(GUILD_ID);
if (connection) {
connection.destroy();
console.log('β
Bot berhasil keluar.');
}
}, {
timezone: "Asia/Jakarta"
});
});
// ========================================================
// FITUR OTOMATIS MULTI-SERVER (RESPON SLASH COMMAND)
// ========================================================
client.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand()) return;
const { commandName, guildId, member } = interaction;
if (commandName === 'join') {
// Otomatis deteksi di Voice Channel mana USER yang mengetik perintah berada
const voiceChannel = member.voice.channel;
if (!voiceChannel) {
return await interaction.reply('β Kamu harus masuk ke salah satu voice room dulu baru panggil aku!');
}
try {
joinVoiceChannel({
channelId: voiceChannel.id,
guildId: guildId,
adapterCreator: voiceChannel.guild.voiceAdapterCreator,
selfDeaf: true
});
await interaction.reply(`π€ Siap! Bot sudah masuk ke room **${voiceChannel.name}**.`);
} catch (error) {
console.error(error);
await interaction.reply('β Gagal masuk, pastikan aku punya izin (permission) di room itu.');
}
}
if (commandName === 'leave') {
const connection = getVoiceConnection(guildId);
if (connection) {
connection.destroy();
await interaction.reply('π€ Bot berhasil keluar dari room server ini.');
} else {
await interaction.reply('βΉοΈ Bot sedang tidak ada di voice room server ini.');
}
}
});
client.login(TOKEN);
// ========================================================
// SERVER WEB SEBAGAI SYARAT HOSTING DI RENDER.COM
// ========================================================
const app = express();
const PORT = process.env.PORT || 3000;
app.get('/', (req, res) => { res.send('π€ Bot Jaga Room Aktif 24/7!'); });
app.listen(PORT, () => { console.log(`π Server web berjalan di port ${PORT}`); });1234567891011121314151617181920{ "name": "bot-discord-timer", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC", "type": "commonjs", "dependencies": { "@discordjs/voice": "^0.19.2", "discord.js": "^14.26.4", "express": "^5.2.1", "ffmpeg-static": "^5.3.0", "node-cron": "^4.2.1" }}index.jsAdded+127
package.jsonAdded+20