Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create access to discord resources from client #216

Open
LeadcodeDev opened this issue Nov 3, 2024 · 1 comment
Open

Create access to discord resources from client #216

LeadcodeDev opened this issue Nov 3, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@LeadcodeDev
Copy link
Member

No description provided.

@LeadcodeDev LeadcodeDev self-assigned this Nov 3, 2024
@LeadcodeDev LeadcodeDev converted this from a draft issue Nov 3, 2024
@LeadcodeDev LeadcodeDev added the enhancement New feature or request label Nov 3, 2024
@NathaelB
Copy link
Member

NathaelB commented Nov 3, 2024

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 case ServerTextChannel 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:

final class TestMessage with InjectClient {
  void handle() {
     final server = client.getServer('...')
     server.channels.getOrFail('...')
    // Code ...
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Backlog
Development

No branches or pull requests

2 participants