Skip to content

devhanachan/Parrot-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

33 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿฆœ Parrot Bot

A feature-rich Discord bot built with TypeScript, Discord.js v14, and Bun runtime. Designed for translation, role management, and server moderation.

Discord.js TypeScript Bun License


โœจ Features

Feature Description
๐ŸŒ Translation Translate text via slash commands or context menu
๐ŸŽญ Self-Roles Interactive role selection panel for members
๐Ÿ—ฃ๏ธ Language Roles Set target translation language via role buttons
๐Ÿ”— URL Moderation Automatic URL detection and removal
๐Ÿ–ผ๏ธ Avatar Fetcher Retrieve any user's profile picture by ID

๐Ÿ“ธ Preview

Context Menu Translation

Context Menu Demo

Role Selection Panel

Role Selection Demo


๐Ÿ“ Project Structure

Parrot-bot/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ commands/
โ”‚   โ”‚   โ”œโ”€โ”€ context/          # Context menu commands
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ translate.ts
โ”‚   โ”‚   โ””โ”€โ”€ slash/            # Slash commands
โ”‚   โ”‚       โ”œโ”€โ”€ langpanel.ts
โ”‚   โ”‚       โ”œโ”€โ”€ ping.ts
โ”‚   โ”‚       โ”œโ”€โ”€ selfroles.ts
โ”‚   โ”‚       โ”œโ”€โ”€ translate.ts
โ”‚   โ”‚       โ””โ”€โ”€ userpfp.ts
โ”‚   โ”œโ”€โ”€ config/
โ”‚   โ”‚   โ””โ”€โ”€ env.ts            # Environment configuration
โ”‚   โ”œโ”€โ”€ constants/
โ”‚   โ”‚   โ”œโ”€โ”€ languages.ts      # Language codes & mappings
โ”‚   โ”‚   โ””โ”€โ”€ roles.ts          # Role configuration
โ”‚   โ”œโ”€โ”€ embeds/
โ”‚   โ”‚   โ””โ”€โ”€ translateEmbed.ts # Translation result embed
โ”‚   โ”œโ”€โ”€ events/
โ”‚   โ”‚   โ”œโ”€โ”€ interactionCreate.ts
โ”‚   โ”‚   โ””โ”€โ”€ messageCreate.ts
โ”‚   โ”œโ”€โ”€ handlers/
โ”‚   โ”‚   โ”œโ”€โ”€ langButtonHandler.ts
โ”‚   โ”‚   โ””โ”€โ”€ selfRolesHandler.ts
โ”‚   โ”œโ”€โ”€ services/
โ”‚   โ”‚   โ””โ”€โ”€ translateService.ts
โ”‚   โ”œโ”€โ”€ types/
โ”‚   โ”‚   โ”œโ”€โ”€ discord.d.ts      # Discord.js type extensions
โ”‚   โ”‚   โ””โ”€โ”€ index.ts          # Shared type definitions
โ”‚   โ”œโ”€โ”€ utils/
โ”‚   โ”‚   โ”œโ”€โ”€ arrays.ts
โ”‚   โ”‚   โ””โ”€โ”€ strings.ts
โ”‚   โ”œโ”€โ”€ main.ts               # Bot entry point
โ”‚   โ””โ”€โ”€ register.ts           # Command registration
โ”œโ”€โ”€ .env                      # Environment variables (not committed)
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ tsconfig.json
โ””โ”€โ”€ README.md

๐Ÿš€ Getting Started

Prerequisites

  • Bun v1.0 or higher
  • Discord Bot Token (Create one here)
  • Node.js 18+ (for Discord.js compatibility)

Installation

1. Clone the repository

git clone https://github.com/your-username/parrot-bot.git
cd parrot-bot

2. Install dependencies

bun install

3. Configure environment variables

Create a .env file in the project root:

TOKEN=your_discord_bot_token
CLIENT_ID=your_application_client_id
GUILD_ID=your_development_server_id  # Optional: for guild-specific commands

4. Register commands

bun run register

5. Start the bot

bun run start

Development Mode

Run with hot reload:

bun run dev

๐Ÿ“‹ Commands

Slash Commands

Command Description Permission
/ping Check bot latency Everyone
/translate Translate text to a specified language Everyone
/stealpfp Get a user's profile picture by ID Everyone
/langpanel Post language role selection panel Administrator
/selfroles Post self-role selection panel Administrator

Context Menu Commands

Command Type Description
Translate (Target Role) Message Translate selected message based on your language role

๐ŸŽฎ Usage Guide

Translation

Slash Command:

/translate msg:Hello, how are you? langcode:ja

Context Menu:

  1. Right-click any message
  2. Navigate to Apps โ†’ Translate (Target Role)
  3. Translation uses your assigned language role (defaults to English)

Language Panel

Administrators can create a language selection panel:

/langpanel

Users click buttons to set their target translation language. Only one language role is active at a time.

Supported Languages:

  • ๐Ÿ‡ฌ๐Ÿ‡ง English (en)
  • ๐Ÿ‡น๐Ÿ‡ญ Thai (th)
  • ๐Ÿ‡ฏ๐Ÿ‡ต Japanese (ja)
  • ๐Ÿ‡ต๐Ÿ‡ญ Filipino (fil)
  • ๐Ÿ‡ฎ๐Ÿ‡ฉ Indonesian (id)
  • ๐Ÿ‡ช๐Ÿ‡ฌ Arabic - Egyptian (ar-eg)
  • ๐Ÿ‡ฌ๐Ÿ‡ญ Akan (ak)
  • ๐Ÿ‡ฌ๐Ÿ‡ญ Ewe (ee)
  • ๐Ÿ‡ฌ๐Ÿ‡ญ Ga (gaa)
  • ๐Ÿ‡ฌ๐Ÿ‡ญ Dagbani (dag)

Self-Roles Panel

Administrators can create a role selection panel:

/selfroles
  • Users select roles from the dropdown menu
  • Press Submit to apply selected roles
  • Press Reset to clear selection
  • Developer role is auto-assigned when submitting

๐Ÿ› ๏ธ Development

Adding a New Slash Command

Create a new file in src/commands/slash/:

import { SlashCommandBuilder } from "discord.js";
import type { Command } from "../../types";

export const command: Command = {
  data: new SlashCommandBuilder()
    .setName("example")
    .setDescription("An example command"),

  async execute(interaction) {
    await interaction.reply("Hello from example command!");
  },
};

Adding a Context Menu Command

Create a new file in src/commands/context/:

import {
  ApplicationCommandType,
  ContextMenuCommandBuilder,
  MessageFlags,
} from "discord.js";
import type { MessageContextMenuCommandInteraction } from "discord.js";
import type { Command } from "../../types";

export const command: Command<MessageContextMenuCommandInteraction> = {
  data: new ContextMenuCommandBuilder()
    .setName("Example Action")
    .setType(ApplicationCommandType.Message),

  async execute(interaction) {
    const message = interaction.targetMessage;
    
    await interaction.reply({
      content: `Message content: ${message.content}`,
      flags: MessageFlags.Ephemeral,
    });
  },
};

After Adding Commands

Register the new commands with Discord:

bun run register

Then restart the bot:

bun run start

๐Ÿ“ Scripts

Script Description
bun run start Start the bot
bun run dev Start with hot reload
bun run register Register commands to Discord
bun run test Run tests with Vitest
bun run lint Type-check with TypeScript

โš™๏ธ Configuration

Environment Variables

Variable Required Description
TOKEN โœ… Discord bot token
CLIENT_ID โœ… Discord application ID
GUILD_ID โŒ Guild ID for dev commands (instant updates)

Role Configuration

Edit src/constants/roles.ts to customize:

  • EXCLUDED_ROLE_NAMES - Roles excluded from self-role selection
  • DEVELOPER_ROLE_NAME - Auto-assigned developer role name

Language Configuration

Edit src/constants/languages.ts to:

  • Add/remove supported languages in LANG_CODES
  • Map language codes to Google Translate codes in TRANSLATE_TARGET

๐Ÿ”ง Troubleshooting

Commands not appearing

  1. Ensure bun run register completed successfully
  2. Check bot has applications.commands scope
  3. Wait up to 1 hour for global commands (instant for guild commands)

Bot missing permissions

Ensure the bot role has:

  • Manage Roles - For role assignment features
  • Send Messages - For responding to commands
  • Manage Messages - For URL moderation

Translation not working

  • Google Translate API may rate-limit frequent requests
  • Check network connectivity
  • Verify the language code is valid

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m "Add: amazing feature")
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


๐Ÿ™ Acknowledgments

About

Hello world!, Parrot is my first bot ever! after learning typescript for a whole month

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

 
 
 

Contributors