custom-discord-bot
Version:
A powerful, customizable Discord bot framework with embeds, cooldowns, aliases, middleware, function commands, and real-time stats ā built with OceanicJS.
217 lines (174 loc) ⢠6.62 kB
Markdown
# Custom Discord Bot š¤
ā
**Free to use!**
ā” A powerful, feature-rich **Discord bot framework** built with Oceanic.js. Create bots in minutes with **embeds, cooldowns, aliases, function commands, middleware, real-time stats**, and more!



---
## š What's New in v3.0.0
š„ **Embed Support** ā Send rich embed messages as command responses
š„ **Cooldown System** ā Prevent command spam with configurable cooldowns
š„ **Command Aliases** ā Multiple triggers for the same command
š„ **Function Commands** ā Execute custom logic with `(message, args) => {}`
š„ **Middleware** ā Intercept and filter messages before command processing
š„ **Dynamic Placeholders** ā Use `{user}`, `{server}`, `{args}`, `{uptime}` in responses
š„ **Runtime Commands** ā Add/remove commands while bot is running
š„ **Event System** ā Listen to `ready`, `message`, `commandUsed`, `error`, `disconnect`
š„ **Bot Stats** ā Track uptime, command usage, and more
š„ **Class-based API** ā New `DiscordBot` class with full control
š„ **100% Backwards Compatible** ā `startBot()` still works!
---
## š¦ Installation
```sh
npm install custom-discord-bot
```
---
## š Quick Start (Simple)
```js
const { startBot } = require("custom-discord-bot");
startBot({
token: "YOUR_DISCORD_BOT_TOKEN",
prefix: "!",
status: "online",
statusMessage: "Listening to commands! š§",
statusType: 2,
cooldown: 3, // 3 second cooldown between commands
commands: {
"ping": "Pong! š",
"hello": "Hello {user}! Welcome to **{server}**! š",
"say": "You said: {args}",
"uptime": "š Bot uptime: {uptime}",
},
aliases: {
"p": "ping",
"hi": "hello",
}
});
```
---
## šļø Advanced Usage (Class API)
```js
const { DiscordBot } = require("custom-discord-bot");
const bot = new DiscordBot({
token: "YOUR_DISCORD_BOT_TOKEN",
prefix: "!",
cooldown: 5,
logCommands: true,
commands: {
"ping": "Pong! š",
// š„ Embed response
"info": DiscordBot.createEmbed({
title: "Bot Information",
description: "I'm a powerful custom bot!",
color: 0xff6b6b,
fields: [
{ name: "Version", value: "3.0.0", inline: true },
{ name: "Library", value: "Oceanic.js", inline: true },
],
footer: "Made with ā¤ļø",
}),
// š„ Function command with custom logic
"roll": (message, args) => {
const max = parseInt(args[0]) || 6;
const result = Math.floor(Math.random() * max) + 1;
message.channel.createMessage({ content: `š² You rolled a **${result}**!` });
},
// š„ Function command with async
"userinfo": async (message, args) => {
const user = message.author;
const embed = DiscordBot.createEmbed({
title: `${user.username}'s Info`,
thumbnail: user.avatarURL(),
fields: [
{ name: "ID", value: user.id, inline: true },
{ name: "Created", value: new Date(user.createdAt).toLocaleDateString(), inline: true },
],
color: 0x5865f2,
});
message.channel.createMessage({ embeds: [embed] });
},
},
aliases: {
"dice": "roll",
"me": "userinfo",
},
});
// š” Event listeners
bot.on("ready", (client) => {
console.log(`Connected to ${client.guilds.size} servers!`);
});
bot.on("commandUsed", ({ command, user, args }) => {
console.log(`š ${user} used !${command} with args: [${args}]`);
});
bot.on("error", (err) => {
console.error("Bot error:", err.message);
});
// š Start the bot
bot.start();
// ā Add commands at runtime
setTimeout(() => {
bot.addCommand("late", "I was added after the bot started! ā°", ["delayed"]);
}, 5000);
```
---
## š Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
| `token` | string | *Required* | Your Discord bot token |
| `prefix` | string | `"!"` | Command prefix |
| `status` | string | `"online"` | Bot status (`online`, `dnd`, `idle`) |
| `statusMessage` | string | `""` | Custom status message |
| `statusType` | number | `0` | Activity type (0: Playing, 1: Streaming, 2: Listening, 3: Watching) |
| `avatarUrl` | string | `""` | Bot avatar URL |
| `username` | string | `""` | Bot username |
| `commands` | object | `{}` | Commands `{ "cmd": "response" \| embedObj \| function }` |
| `aliases` | object | `{}` | Aliases `{ "alias": "originalCommand" }` |
| `cooldown` | number | `0` | Cooldown per user per command in seconds |
| `onReady` | function | `null` | Callback when bot is ready |
| `onMessage` | function | `null` | Message middleware (return `false` to block) |
| `onError` | function | `null` | Custom error handler |
| `autoReconnect` | boolean | `true` | Auto-reconnect on disconnect |
| `logCommands` | boolean | `true` | Log command usage to console |
---
## š§© Response Types
### String Response (with placeholders)
```js
"Hello {user}! Welcome to {server}!"
```
Available: `{user}`, `{server}`, `{args}`, `{uptime}`
### Embed Response
```js
DiscordBot.createEmbed({
title: "My Embed",
description: "Rich embed content",
color: 0xff0000,
fields: [{ name: "Field", value: "Value", inline: true }],
footer: "Footer text",
thumbnail: "https://example.com/image.png",
image: "https://example.com/banner.png",
})
```
### Function Response
```js
(message, args) => {
message.channel.createMessage({ content: `You said: ${args.join(" ")}` });
}
```
---
## š Bot Stats
```js
const stats = bot.getStats();
console.log(stats);
// { uptime: "2h 15m 30s", totalCommands: 142, commandBreakdown: { ping: 50, hello: 92 }, ... }
```
---
## š ļø Contributing
Pull requests are welcome! Fork the repo, create a branch, and submit a PR. š
---
## š License
This project is licensed under the **MIT License**.
---
## š Support & Contact
- **GitHub Issues:** [Report Bugs or Request Features](https://github.com/utkuberkaykoc/custom-discord-bot/issues)
- **Give a Star:** ā If you love this package, show some support!
š **Now go build something awesome!** š®āØ