discord_bot_flutter 1.0.0
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 #
-
Go to the Discord Developer Portal
-
Create a new application
-
Navigate to Bot β Add Bot
-
Copy the Bot Token
-
Enable required permissions:
- Send Messages
-
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.fromEnvironmentrequires 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:
- Fork the repository
- Create a feature branch
- 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!