Fundamentals
Context menus
With the arrival of version 9 of the Discord platform API, we now have the ability to perform actions from users or messages. Context Menus are application commands which appear when right-clicking or tapping a user or a message, in the Apps submenu.
See more about version 9
Basic usage
To simplify the creation of context menus files, the CLI provides you with an initialisation command.
dart run mineral make:menu <MyMenu>
A question/answer game then appears, asking you to select an event from among those available in the database.
The context menu
The mineral framework provide you with dedicated classes, please consider the examples below.
import 'package:mineral/framework';
import 'package:mineral/core/api';
class FooContextMenu extends MineralContextMenu<Message> {
FooContextMenu(): super('get-message-content', ContextMenuType.message);
Future<void> handle (message) async {
await interaction.reply(content: message.content);
}
}
In our example, we execute a statement when a user is targeted is used in the interaction but you can totally use the component for in the context of messages.
In this following example, you can trigger a user report to execute some actions.
import 'package:mineral/framework';
import 'package:mineral/core/api';
class FooContextMenu extends MineralContextMenu<User> {
FooContextMenu(): super('get-user', ContextMenuType.user);
Future<void> handle (user) async {
await interaction.reply(content: user.username);
}
}