UNPKG

robtic-discord-startup

Version:

easily set up a Discord bot with configurable settings

174 lines (137 loc) 5.72 kB
# Discord Bot Login A TypeScript package to easily set up a Discord bot with configurable settings, commands, and components. ## Features * **Robust Error Handling:** Includes a comprehensive error handler system that pinpoints issues with precise file paths, making debugging quick and efficient. * **High Performance and Stability:** Designed for fast execution and reliable operation, ensuring your bot runs smoothly even under heavy load. * **Automatic Dependency Installation:** Seamlessly installs the discord.js package as a dependency, simplifying setup and ensuring compatibility. * **Type-Safe Development:** Built with TypeScript and includes safety types to catch errors early, providing a safer and more predictable development experience. * **Customizable Embed System:** Features a new, user-friendly embed system that allows easy customization of Discord embeds with minimal effort. ## Installation Install the package using Bun or npm: ```bash bunx create-robtic-app my-app # or npx create-robtic-app my-app # for typescript bunx create-robtic-app my-app --template=typescript # same with npx ``` ## Setup Follow these steps to set up your Discord bot using `robtic-discord-startup`. ### 1. Edit a Configuration File > Edit `robtic.config` to include your bot’s token, client ID, and other settings. Example: ```ts import { defineConfig } from "robtic-discord-startup"; export default defineConfig({ starter: { token: "YOUR_BOT_TOKEN_HERE", clientId: "YOUR_BOT_CLIENT_ID_HERE", //mongoURL: "", // you can add it if you will use data //clientSecret: "", }, activity: { text: "Robtic package" }, slashcommand: { defaultCooldown: 5, ownerOnly: false }, access: { CEO: { roles: { name: ["CEO Role Name"], id: ["CEO Role Id"] }, perms: ["Administrator"] } // you can add admin , support , mod }, intents: [ "Guilds", "GuildMessages", "MessageContent" // more intents here ] }); ``` ### 2. Create Commands and Events Folders * Create a `commands` folder in your project root to store your bot commands. * Create a `Events` folder in your project root to store your bot Events (e.g., buttons, modals, etc.). > Example Command `(commands/ping.ts)` : ```ts import { Command } from "robtic-discord-startup"; import { SlashCommandBuilder } from "discord.js"; export default new Command ({ data: new SlashCommandBuilder() .setName("ping") .setDescription("Replies with Pong!"), admin: true, // for check access you can remove it or replace it with false run: async (interaction) => { await interaction.reply("Pong!"); } }) ``` > `Note:` use Command function from the package for safty types . ### 3. Start the Bot * in an `index.ts` file (or any entry point) in your project root with the following code: ```ts import { Bot, db } from "robtic-discord-startup" const bot = new Bot(); bot.start(); // db.connect(); // connect to db if you use data using mongoDB ``` Run your project: ```bash bun run start # or npm run start ``` ## Project Structure ```bash your-project/ ├── src/ ├ ├── commands/ ├ │ └── ping.ts ├ ├── components/ ├ │ └── example.ts ├ └── index.ts # entrypoint file ├── robtic.config.ts # config file ├── package.json └── bun.lockb # lock file for bun ( package-lock for npm ) ``` ## Configuration Options The `robtic.config` file supports the following options: * **starter:** * token: Your bot’s Discord token (required). * clientId: Your bot’s client ID (required). * clientSecret: Optional client secret for OAuth2. * mongoURL: Optional MongoDB connection URL for database integration. * **activity:** * text: The bot’s activity text (e.g., "Playing Robtic package"). * type: Optional activity type (e.g., "PLAYING", "WATCHING"). * status: Optional status (e.g., "online", "dnd"). * **slashcommand:** * defaultCooldown: Default cooldown for commands in seconds (default: 5). * ownerOnly: Restrict commands to bot owners (default: false). * embedDefault: support only footer and author for bot copyright * **access:** (CEO, admin, mod, support) * CEO: Role settings for bot administrators. * roles.name: Array of role names. * roles.id: Array of role IDs. * perms: Array of permissions (e.g., ["Administrator"]). * **intents:** Array of Discord intents (e.g., ["Guilds", "GuildMessages", "MessageContent"]). * **paths:** use can select any folder source name to make it your commands or events folder using ( `CommandPaths`, `EventsPaths` ) ## Troubleshooting 1. "⚠️ robtic.config.ts not found in your project": * Ensure you’ve created the `robtic.config.ts` file as described in the setup steps. 2. Commands or components not loading: * Verify that the `commands` and `Events` folders exist in your project root and contain valid `.ts` or `.js` files. * Check that your `command` files export a default object with `data` and `run` properties. * Check that your `Events` files export a default object with `name` and `execute` properties. 3. "Invalid Bot Token": * Double-check that the token in `robtic.config` is correct and hasn’t expired. 4. Other Errors: * Ensure you’re using the correct versions of dependencies (e.g., `discord.js`). ## Contributing Contributions are welcome! Please submit a pull request or open an issue on the GitHub repository. ## License This package is licensed under the MIT License. See the [LICENSE](https://github.com/RoBoCRAFTYT01/robtic-discord-startup?tab=MIT-1-ov-file) file for details.