discord_bot_flutter 1.0.0 copy "discord_bot_flutter: ^1.0.0" to clipboard
discord_bot_flutter: ^1.0.0 copied to clipboard

A dart package to interact with discord bot

Discord Bot Flutter #

A lightweight Dart package to interact with the Discord Bot API. This package currently supports sending text messages to Discord channels using a bot.


✨ Features #

  • Send text messages to a Discord channel
  • Simple and minimal API
  • Easy integration with Dart & Flutter projects
  • Supports environment-based configuration (--define)

πŸš€ Getting Started #

Prerequisites #

Before using this package, make sure you have:

  • A Discord account
  • A Discord server
  • A bot created via the Discord Developer Portal
  • Bot token
  • Channel ID where messages will be sent

πŸ”§ Setup Discord Bot #

  1. Go to the Discord Developer Portal

  2. Create a new application

  3. Navigate to Bot β†’ Add Bot

  4. Copy the Bot Token

  5. Enable required permissions:

    • Send Messages
  6. Invite the bot to your server


πŸ“¦ Installation #

Add the package to your pubspec.yaml:

dependencies:
  discord_bot_flutter: ^latest

Then run:

# For dart project
dart pub get

# For Flutter Project
flutter pub get

πŸ’‘ Usage #

It is recommended to pass sensitive values (like tokens) using --define.

▢️ Run with environment values #

Create .env file:

DISCORD_BOT_TOKEN=your_bot_token
DISCORD_CHANNEL_ID=your_channel_id

For dart project:

dart run \
  --define=DISCORD_BOT_TOKEN=your_bot_token \
  --define=DISCORD_CHANNEL_ID=your_channel_id \
  bin/main.dart

For Flutter project:

flutter run --dart-define-from-file=.env

πŸ§ͺ Example #

import 'package:discord_bot_flutter/discord_bot_flutter.dart';

const botToken = String.fromEnvironment('DISCORD_BOT_TOKEN');
const channelId = String.fromEnvironment('DISCORD_CHANNEL_ID');

void main() async {
  final bot = DiscordBotFlutter(
    channelID: channelId,
    botToken: botToken,
  );

  await bot.sendMessageAsText(
    "A user named John Doe has joined the channel πŸš€",
  );
}

⚠️ Important Notes #

  • String.fromEnvironment requires values to be passed using --define
  • These values are compile-time constants
  • Do NOT hardcode your bot token in source code
  • Never commit secrets to version control

πŸ› οΈ Current Limitations #

  • Only supports sending text messages

  • No support yet for:

    • Embeds
    • Attachments
    • Slash commands
    • Interaction events

πŸ—ΊοΈ Roadmap #

  • ❌ Embed message support
  • ❌ File uploads
  • ❌ Slash command handling
  • ❌ Webhook support
  • ❌ Better error handling

🀝 Contributing #

Contributions are welcome!

If you'd like to improve this package:

  1. Fork the repository
  2. Create a feature branch
  3. Submit a pull request

πŸ› Issues #

If you encounter any issues or bugs, please open an issue in the repository with:

  • Steps to reproduce
  • Expected behavior
  • Actual behavior

πŸ“„ License #

This project is licensed under the MIT License.


❀️ Support #

If you find this package useful, consider giving it a ⭐ on GitHub!