You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The aim is to be able to access server, channel and other objects in any class.
For example, in the context of an external call (HTTP, AMQP, Redis, etc.), to be able to retrieve a channel/server and interact with it.
For example, how to retrieve a server, a channel and send a message on the channel:
Future<void> main(_, port) async {
final client =Client().setCache((e) =>MemoryProvider()).setHmrDevPort(port).build();
client.events.ready((Bot bot) {
client.logger.info('${bot.username} is ready ! 🚀');
});
final nats =Nats();
await nats.connect();
final natsClient = nats.client;
final sub = natsClient.sub('messages');
client.events.server.serverCreate((Server server) {
final channel = server.channels.getOrFail('1302764876120195143');
sub.stream.listen((msg) async {
final str =String.fromCharCodes(msg.data);
client.logger.info('Received message: ${str}');
if (channel caseServerTextChannel channel) {
final embed =MessageEmbedBuilder()
.setTitle('Test')
.setDescription("Message reçu: $str")
.setColor(Color.cyan_200)
.build();
await channel.send(embeds: [embed], content:'Message contenant un embed');
}
});
});
await client.init();
}
We could imagine something like that:
finalclassTestMessagewithInjectClient {
voidhandle() {
final server = client.getServer('...')
server.channels.getOrFail('...')
// Code ...
}
}
No description provided.
The text was updated successfully, but these errors were encountered: