DZ-Musicbot/index.js

89 lines
2.8 KiB
JavaScript
Raw Normal View History

2024-08-17 11:11:10 -04:00
const { Client, GatewayIntentBits } = require('discord.js');
const fs = require('fs');
const path = require('path');
const { prefix, token } = require('./config.json');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
client.commands = new Map();
const tmpDir = path.join(__dirname, 'utils', 'tmp');
if (!fs.existsSync(tmpDir)) {
fs.mkdirSync(tmpDir, { recursive: true });
}
fs.readdir(tmpDir, (err, files) => {
if (err) throw err;
for (const file of files) {
2024-10-21 11:27:46 -04:00
if (file.endsWith('.mp3') || file.endsWith('.part')) {
2024-08-17 15:11:10 -04:00
fs.unlink(path.join(tmpDir, file), err => {
if (err) throw err;
});
}
}
});
2024-08-17 11:11:10 -04:00
const commandFiles = fs.readdirSync(path.join(__dirname, 'commands')).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
2024-10-21 11:27:46 -04:00
const blacklistPath = path.join(__dirname, 'blacklist.json');
if (!fs.existsSync(blacklistPath)) {
console.log('blacklist.json not found, creating one...');
fs.writeFileSync(blacklistPath, JSON.stringify({ blacklisted: [] }, null, 2));
}
let blacklistData = JSON.parse(fs.readFileSync(blacklistPath, 'utf8'));
let blacklist = blacklistData.blacklisted;
2024-08-17 11:11:10 -04:00
client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
2024-08-17 17:45:26 -04:00
client.user.setStatus('idle');
const statuses = require('./statuses.json');
function updateStatus() {
const randomStatus = statuses[Math.floor(Math.random() * statuses.length)];
client.user.setActivity(randomStatus);
console.log(`Activity set to: ${randomStatus}`);
}
updateStatus();
setInterval(updateStatus, 30000);
2024-08-17 11:11:10 -04:00
});
client.on('messageCreate', async message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
2024-10-21 11:27:46 -04:00
if (blacklist.includes(message.author.id)) {
return message.reply("You are blacklisted from using this bot.");
}
2024-08-17 11:11:10 -04:00
const args = message.content.slice(prefix.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase();
2024-08-17 20:13:09 -04:00
const command = client.commands.get(commandName) ||
Array.from(client.commands.values()).find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
if (!command) return;
2024-08-17 11:11:10 -04:00
try {
2024-08-17 20:13:09 -04:00
await command.execute(message, args);
2024-08-17 11:11:10 -04:00
} catch (error) {
console.error(error);
message.reply('There was an error trying to execute that command!');
}
});
2024-10-21 11:27:46 -04:00
function updateBlacklist(newBlacklist) {
blacklist = newBlacklist;
console.log("Blacklist updated:", blacklist);
}
module.exports = { updateBlacklist };
2024-08-17 11:11:10 -04:00
client.login(token);