Installation
Before embarking on this crazy discord adventure, you will need to follow the steps outlined below to set up a clean and healthy project.
Prerequisites
Please make sure you have the following tools installed on your machine before you start.
Dart lang
The Mineral framework has been developed entirely in the Dart programming language, so you will need to install it in your development environment first. In order to best install it, please refer to the official documentation.
The version of the Dart language sdk must be at least ^3.5.2
.
Installation
From the CLI
You can use the Mineral CLI to create a new project.
Follow the steps below to install the CLI.
dart pub global activate mineral_cli [version]
cd path/to/your/projects
mineral create my_project
More details about the CLI can be found in the CLI section.
From scratch
Use the following command to start a new blank Dart project.
dart create my_project
After creating the project, you will need to add the Mineral framework to your pubspec.yaml
file.
dependencies:
mineral: ^4.0.0-dev.6
mineral_cache: ^1.0.0-dev.3
Then run the following command to install the dependencies.
dart pub get
Explore
Project structure
You should have an directory named bin
in your project root. This is where you will put all your source code.
├── bin
│ └── main.dart
│
├── lib
│
├── pubspec.yaml
└── .env
You can also consult the structure section for more information about the structure of your project.
Environment variables
To make the whole project work, you will need to create an .env
file at the root of your project.
DART_ENV=
TOKEN=
DISCORD_REST_API_VERSION=
DISCORD_WS_VERSION=
INTENT=
LOG_LEVEL=
You can also consult the environment variables section for more information about the configuration of your project.
Main entrypoint
The main.dart
file is the entry point of your application. This is where you will start your bot.
import 'package:mineral/api.dart';
import 'package:mineral_cache/providers/memory.dart';
void main(_, port) async {
final client = ClientBuilder()
.setCache((e) => MemoryProvider())
.setHmrDevPort(port)
.build();
await client.init();
}
To check that your application is working properly, we recommend that you use the ready
event.
You can remove it after checking.
import 'package:mineral/api.dart';
import 'package:mineral_cache/providers/memory.dart';
void main(_, port) async {
final client = ClientBuilder()
.setCache((e) => MemoryProvider())
.setHmrDevPort(port)
.build();
client.events.ready((Bot bot) {
client.logger.info('${bot.username} is ready ! 🚀');
});
await client.init();
}
Running the application
Finally, you can run your application with the following command.
dart run src/main.dart