mirror of
https://github.com/aydenjahola/discord-multipurpose-bot.git
synced 2025-09-21 14:51:34 +01:00
seperate distube and change startup console theme
This commit is contained in:
parent
fc60a544ff
commit
f62bbc4ab7
2 changed files with 279 additions and 49 deletions
113
events/distubeEvents.js
Normal file
113
events/distubeEvents.js
Normal file
|
@ -0,0 +1,113 @@
|
||||||
|
const { EmbedBuilder } = require("discord.js");
|
||||||
|
|
||||||
|
module.exports = (distube, botName) => {
|
||||||
|
const footerConfig = {
|
||||||
|
text: `Powered by ${botName}, developed with ❤️ by Ayden`,
|
||||||
|
iconURL: "https://github.com/aydenjahola.png",
|
||||||
|
};
|
||||||
|
|
||||||
|
const createEmbed = (color, title, description, thumbnail = null) => {
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor(color)
|
||||||
|
.setTitle(title)
|
||||||
|
.setDescription(description)
|
||||||
|
.setFooter(footerConfig);
|
||||||
|
|
||||||
|
if (thumbnail) {
|
||||||
|
embed.setThumbnail(thumbnail);
|
||||||
|
}
|
||||||
|
|
||||||
|
return embed;
|
||||||
|
};
|
||||||
|
|
||||||
|
distube
|
||||||
|
.on("playSong", (queue, song) => {
|
||||||
|
const embed = createEmbed(
|
||||||
|
0x0099ff,
|
||||||
|
"🎶 Now Playing",
|
||||||
|
`**${song.name}** - \`${song.formattedDuration}\``,
|
||||||
|
song.thumbnail
|
||||||
|
);
|
||||||
|
queue.textChannel.send({ embeds: [embed] });
|
||||||
|
})
|
||||||
|
.on("addSong", (queue, song) => {
|
||||||
|
const embed = createEmbed(
|
||||||
|
0x00ff00,
|
||||||
|
"✅ Song Added",
|
||||||
|
`**${song.name}** - \`${song.formattedDuration}\``,
|
||||||
|
song.thumbnail
|
||||||
|
);
|
||||||
|
queue.textChannel.send({ embeds: [embed] });
|
||||||
|
})
|
||||||
|
.on("error", (channel, error) => {
|
||||||
|
console.error("DisTube error:", error);
|
||||||
|
const embed = createEmbed(
|
||||||
|
0xff0000,
|
||||||
|
"❌ Error",
|
||||||
|
`An error occurred: ${error.message}`
|
||||||
|
);
|
||||||
|
if (channel && channel.send) {
|
||||||
|
channel.send({ embeds: [embed] });
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.on("finish", (queue) => {
|
||||||
|
if (queue.textChannel) {
|
||||||
|
const embed = createEmbed(
|
||||||
|
0x0099ff,
|
||||||
|
"🎵 Queue Finished",
|
||||||
|
"The music queue has ended."
|
||||||
|
);
|
||||||
|
queue.textChannel.send({ embeds: [embed] });
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.on("pause", (queue) => {
|
||||||
|
if (queue.textChannel) {
|
||||||
|
const embed = createEmbed(
|
||||||
|
0xffff00,
|
||||||
|
"⏸️ Music Paused",
|
||||||
|
"Playback has been paused."
|
||||||
|
);
|
||||||
|
queue.textChannel.send({ embeds: [embed] });
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.on("resume", (queue) => {
|
||||||
|
if (queue.textChannel) {
|
||||||
|
const embed = createEmbed(
|
||||||
|
0x00ff00,
|
||||||
|
"▶️ Music Resumed",
|
||||||
|
"Playback has been resumed."
|
||||||
|
);
|
||||||
|
queue.textChannel.send({ embeds: [embed] });
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.on("volumeChange", (queue, volume) => {
|
||||||
|
if (queue.textChannel) {
|
||||||
|
const embed = createEmbed(
|
||||||
|
0x0099ff,
|
||||||
|
"🔊 Volume Changed",
|
||||||
|
`Volume set to ${volume}%`
|
||||||
|
);
|
||||||
|
queue.textChannel.send({ embeds: [embed] });
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.on("noRelated", (queue) => {
|
||||||
|
if (queue.textChannel) {
|
||||||
|
const embed = createEmbed(
|
||||||
|
0xff0000,
|
||||||
|
"❌ No Related Videos",
|
||||||
|
"Could not find related video for autoplay!"
|
||||||
|
);
|
||||||
|
queue.textChannel.send({ embeds: [embed] });
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.on("empty", (queue) => {
|
||||||
|
if (queue.textChannel) {
|
||||||
|
const embed = createEmbed(
|
||||||
|
0xff0000,
|
||||||
|
"🔇 Voice Channel Empty",
|
||||||
|
"Voice channel is empty! Leaving the channel."
|
||||||
|
);
|
||||||
|
queue.textChannel.send({ embeds: [embed] });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
215
index.js
215
index.js
|
@ -16,6 +16,56 @@ const path = require("path");
|
||||||
const ServerSettings = require("./models/ServerSettings");
|
const ServerSettings = require("./models/ServerSettings");
|
||||||
const seedShopItems = require("./utils/seedShopItems");
|
const seedShopItems = require("./utils/seedShopItems");
|
||||||
const seedSpyfallLocations = require("./utils/seedSpyfallLocations");
|
const seedSpyfallLocations = require("./utils/seedSpyfallLocations");
|
||||||
|
const setupDisTubeEvents = require("./events/distubeEvents");
|
||||||
|
|
||||||
|
// Console colors
|
||||||
|
const colors = {
|
||||||
|
reset: "\x1b[0m",
|
||||||
|
bright: "\x1b[1m",
|
||||||
|
dim: "\x1b[2m",
|
||||||
|
underscore: "\x1b[4m",
|
||||||
|
blink: "\x1b[5m",
|
||||||
|
reverse: "\x1b[7m",
|
||||||
|
hidden: "\x1b[8m",
|
||||||
|
|
||||||
|
black: "\x1b[30m",
|
||||||
|
red: "\x1b[31m",
|
||||||
|
green: "\x1b[32m",
|
||||||
|
yellow: "\x1b[33m",
|
||||||
|
blue: "\x1b[34m",
|
||||||
|
magenta: "\x1b[35m",
|
||||||
|
cyan: "\x1b[36m",
|
||||||
|
white: "\x1b[37m",
|
||||||
|
|
||||||
|
bgBlack: "\x1b[40m",
|
||||||
|
bgRed: "\x1b[41m",
|
||||||
|
bgGreen: "\x1b[42m",
|
||||||
|
bgYellow: "\x1b[43m",
|
||||||
|
bgBlue: "\x1b[44m",
|
||||||
|
bgMagenta: "\x1b[45m",
|
||||||
|
bgCyan: "\x1b[46m",
|
||||||
|
bgWhite: "\x1b[47m",
|
||||||
|
};
|
||||||
|
|
||||||
|
const printBanner = () => {
|
||||||
|
console.log(`${colors.magenta}
|
||||||
|
██████╗██╗██████╗ ██████╗ ██╗ ██╗██████╗ ████████╗██████╗ ██╗██╗ ██╗
|
||||||
|
██╔════╝██║██╔══██╗██╔══██╗██║ ██║██╔══██╗╚══██╔══╝██╔══██╗██║╚██╗██╔╝
|
||||||
|
██║ ██║██████╔╝██████╔╝██║ ██║██████╔╝ ██║ ██████╔╝██║ ╚███╔╝
|
||||||
|
██║ ██║██╔══██╗██╔══██╗██║ ██║██╔══██╗ ██║ ██╔══██╗██║ ██╔██╗
|
||||||
|
╚██████╗██║██║ ██║██║ ██║╚██████╔╝██║ ██║ ██║ ██║ ██║██║██╔╝ ██╗
|
||||||
|
╚═════╝╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═╝
|
||||||
|
${colors.reset}`);
|
||||||
|
console.log(
|
||||||
|
`${colors.cyan}${colors.bright}⚡ Circuitrix Discord Bot ${colors.reset}`
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
`${colors.cyan}${colors.bright}✨ Developed with ❤️ by Ayden ${colors.reset}`
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
`${colors.cyan}${colors.bright}🌐 https://github.com/aydenjahola ${colors.reset}\n`
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
intents: [
|
intents: [
|
||||||
|
@ -34,38 +84,6 @@ client.distube = new DisTube(client, {
|
||||||
plugins: [new SpotifyPlugin(), new SoundCloudPlugin()],
|
plugins: [new SpotifyPlugin(), new SoundCloudPlugin()],
|
||||||
});
|
});
|
||||||
|
|
||||||
// DisTube event listeners
|
|
||||||
client.distube
|
|
||||||
.on("playSong", (queue, song) => {
|
|
||||||
queue.textChannel.send(
|
|
||||||
`🎶 Playing: **${song.name}** - \`${song.formattedDuration}\``
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.on("addSong", (queue, song) => {
|
|
||||||
queue.textChannel.send(
|
|
||||||
`✅ Added: **${song.name}** - \`${song.formattedDuration}\``
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.on("error", (queue, error) => {
|
|
||||||
console.error("DisTube error:", error);
|
|
||||||
queue.textChannel.send("❌ An error occurred: " + error.message);
|
|
||||||
})
|
|
||||||
.on("finish", (queue) => {
|
|
||||||
queue.textChannel.send("🎵 Queue finished!");
|
|
||||||
})
|
|
||||||
.on("pause", (queue) => {
|
|
||||||
queue.textChannel.send("⏸️ Music paused!");
|
|
||||||
})
|
|
||||||
.on("resume", (queue) => {
|
|
||||||
queue.textChannel.send("▶️ Music resumed!");
|
|
||||||
})
|
|
||||||
.on("volumeChange", (queue, volume) => {
|
|
||||||
queue.textChannel.send(`🔊 Volume changed to ${volume}%`);
|
|
||||||
})
|
|
||||||
.on("noRelated", (queue) => {
|
|
||||||
queue.textChannel.send("❌ Could not find related video for autoplay!");
|
|
||||||
});
|
|
||||||
|
|
||||||
// Function to recursively read commands from subdirectories
|
// Function to recursively read commands from subdirectories
|
||||||
function loadCommands(dir) {
|
function loadCommands(dir) {
|
||||||
const files = fs.readdirSync(dir);
|
const files = fs.readdirSync(dir);
|
||||||
|
@ -74,13 +92,32 @@ function loadCommands(dir) {
|
||||||
if (fs.statSync(filePath).isDirectory()) {
|
if (fs.statSync(filePath).isDirectory()) {
|
||||||
loadCommands(filePath);
|
loadCommands(filePath);
|
||||||
} else if (file.endsWith(".js")) {
|
} else if (file.endsWith(".js")) {
|
||||||
const command = require(filePath);
|
try {
|
||||||
client.commands.set(command.data.name, command);
|
const command = require(filePath);
|
||||||
|
if (command.data && command.data.name) {
|
||||||
|
client.commands.set(command.data.name, command);
|
||||||
|
console.log(
|
||||||
|
`${colors.green}✅ Loaded command: ${colors.reset}${colors.cyan}/${command.data.name}${colors.reset}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(
|
||||||
|
`${colors.red}❌ Failed to load command: ${filePath}${colors.reset}`
|
||||||
|
);
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load commands
|
||||||
|
console.log(
|
||||||
|
`${colors.yellow}${colors.bright}📦 Loading commands...${colors.reset}`
|
||||||
|
);
|
||||||
loadCommands(path.join(__dirname, "commands"));
|
loadCommands(path.join(__dirname, "commands"));
|
||||||
|
console.log(
|
||||||
|
`${colors.green}✅ Successfully loaded ${colors.bright}${client.commands.size}${colors.reset}${colors.green} commands!${colors.reset}\n`
|
||||||
|
);
|
||||||
|
|
||||||
async function registerCommands(guildId) {
|
async function registerCommands(guildId) {
|
||||||
const commands = client.commands.map((cmd) => cmd.data.toJSON());
|
const commands = client.commands.map((cmd) => cmd.data.toJSON());
|
||||||
|
@ -89,18 +126,38 @@ async function registerCommands(guildId) {
|
||||||
await rest.put(Routes.applicationGuildCommands(client.user.id, guildId), {
|
await rest.put(Routes.applicationGuildCommands(client.user.id, guildId), {
|
||||||
body: commands,
|
body: commands,
|
||||||
});
|
});
|
||||||
console.log(`🔄 Registered commands for guild: ${guildId}`);
|
console.log(
|
||||||
|
`${colors.green}🔄 Registered ${colors.bright}${commands.length}${colors.reset}${colors.green} commands for guild: ${colors.cyan}${guildId}${colors.reset}`
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error registering commands:", error);
|
console.log(
|
||||||
|
`${colors.red}❌ Error registering commands for guild ${guildId}:${colors.reset}`
|
||||||
|
);
|
||||||
|
console.error(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
client.once("ready", async () => {
|
client.once("ready", async () => {
|
||||||
console.log(`\n==============================`);
|
printBanner();
|
||||||
console.log(`🤖 Logged in as ${client.user.tag}`);
|
|
||||||
console.log(`==============================`);
|
console.log(
|
||||||
|
`${colors.green}${colors.bright}🚀 Bot successfully logged in as ${colors.cyan}${client.user.tag}${colors.reset}`
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
`${colors.green}${colors.bright}📊 Serving ${colors.cyan}${client.guilds.cache.size}${colors.reset}${colors.green} servers${colors.reset}`
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
`${colors.green}${colors.bright}👥 Watching ${colors.cyan}${client.users.cache.size}${colors.reset}${colors.green} users${colors.reset}\n`
|
||||||
|
);
|
||||||
|
|
||||||
|
// Set up DisTube events
|
||||||
|
setupDisTubeEvents(client.distube, client.user.username);
|
||||||
|
|
||||||
const guilds = client.guilds.cache.map((guild) => guild.id);
|
const guilds = client.guilds.cache.map((guild) => guild.id);
|
||||||
|
console.log(
|
||||||
|
`${colors.yellow}${colors.bright}⚙️ Initializing server configurations...${colors.reset}`
|
||||||
|
);
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
guilds.map(async (guildId) => {
|
guilds.map(async (guildId) => {
|
||||||
await seedShopItems(guildId);
|
await seedShopItems(guildId);
|
||||||
|
@ -110,29 +167,53 @@ client.once("ready", async () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
client.user.setPresence({
|
client.user.setPresence({
|
||||||
activities: [{ name: "Powering Servers!", type: 3 }],
|
activities: [{ name: "Powering Servers! 🚀", type: 3 }],
|
||||||
status: PresenceUpdateStatus.Online,
|
status: PresenceUpdateStatus.Online,
|
||||||
});
|
});
|
||||||
console.log(`\n==============================\n`);
|
|
||||||
|
console.log(
|
||||||
|
`\n${colors.green}${colors.bright}🎉 Bot is now fully operational and ready!${colors.reset}`
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
`${colors.cyan}${colors.bright}==============================================${colors.reset}\n`
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on("guildCreate", async (guild) => {
|
client.on("guildCreate", async (guild) => {
|
||||||
try {
|
try {
|
||||||
await ServerSettings.create({ guildId: guild.id });
|
await ServerSettings.create({ guildId: guild.id });
|
||||||
console.log(`✅ Registered new server: ${guild.name} (ID: ${guild.id})`);
|
console.log(
|
||||||
|
`${colors.green}✅ Registered new server: ${colors.cyan}${guild.name}${colors.reset} ${colors.dim}(${guild.id})${colors.reset}`
|
||||||
|
);
|
||||||
await seedShopItems(guild.id);
|
await seedShopItems(guild.id);
|
||||||
await seedSpyfallLocations(guild.id);
|
await seedSpyfallLocations(guild.id);
|
||||||
await registerCommands(guild.id);
|
await registerCommands(guild.id);
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`${colors.green}🎉 Successfully initialized ${colors.cyan}${guild.name}${colors.reset}${colors.green} with all features!${colors.reset}`
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error registering new server or commands:", error);
|
console.log(`${colors.red}❌ Error registering new server:${colors.reset}`);
|
||||||
|
console.error(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// MongoDB connection
|
// MongoDB connection
|
||||||
|
console.log(
|
||||||
|
`${colors.yellow}${colors.bright}🔗 Connecting to MongoDB...${colors.reset}`
|
||||||
|
);
|
||||||
mongoose
|
mongoose
|
||||||
.connect(process.env.MONGODB_URI)
|
.connect(process.env.MONGODB_URI)
|
||||||
.then(() => console.log("✅ Connected to MongoDB"))
|
.then(() => {
|
||||||
.catch((err) => console.error("❌ Failed to connect to MongoDB", err));
|
console.log(
|
||||||
|
`${colors.green}✅ Successfully connected to MongoDB!${colors.reset}\n`
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(`${colors.red}❌ Failed to connect to MongoDB:${colors.reset}`);
|
||||||
|
console.error(err);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
|
||||||
client.on("interactionCreate", async (interaction) => {
|
client.on("interactionCreate", async (interaction) => {
|
||||||
if (!interaction.isCommand()) return;
|
if (!interaction.isCommand()) return;
|
||||||
|
@ -141,9 +222,12 @@ client.on("interactionCreate", async (interaction) => {
|
||||||
try {
|
try {
|
||||||
await command.execute(interaction, client);
|
await command.execute(interaction, client);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Error executing command:", err);
|
console.log(
|
||||||
|
`${colors.red}❌ Error executing command ${colors.cyan}/${interaction.commandName}${colors.reset}`
|
||||||
|
);
|
||||||
|
console.error(err);
|
||||||
const replyOptions = {
|
const replyOptions = {
|
||||||
content: "Error executing command!",
|
content: "❌ There was an error while executing this command!",
|
||||||
ephemeral: true,
|
ephemeral: true,
|
||||||
};
|
};
|
||||||
if (interaction.deferred || interaction.replied) {
|
if (interaction.deferred || interaction.replied) {
|
||||||
|
@ -154,5 +238,38 @@ client.on("interactionCreate", async (interaction) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on("error", (err) => console.error("Client error:", err));
|
client.on("error", (err) => {
|
||||||
client.login(process.env.BOT_TOKEN);
|
console.log(`${colors.red}${colors.bright}⚠️ Client error:${colors.reset}`);
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
process.on("unhandledRejection", (error) => {
|
||||||
|
console.log(
|
||||||
|
`${colors.red}${colors.bright}⚠️ Unhandled promise rejection:${colors.reset}`
|
||||||
|
);
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
process.on("uncaughtException", (error) => {
|
||||||
|
console.log(
|
||||||
|
`${colors.red}${colors.bright}⚠️ Uncaught exception:${colors.reset}`
|
||||||
|
);
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Login
|
||||||
|
console.log(
|
||||||
|
`${colors.yellow}${colors.bright}🔐 Logging in to Discord...${colors.reset}`
|
||||||
|
);
|
||||||
|
client
|
||||||
|
.login(process.env.BOT_TOKEN)
|
||||||
|
.then(() => {
|
||||||
|
console.log(
|
||||||
|
`${colors.green}✅ Authentication successful!${colors.reset}\n`
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log(`${colors.red}❌ Failed to login to Discord:${colors.reset}`);
|
||||||
|
console.error(error);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue