selene 0.1.0 copy "selene: ^0.1.0" to clipboard
selene: ^0.1.0 copied to clipboard

outdatedDart 1 only

Predictable Dart bindings for the Discord API.

example/selene_example.dart

import 'dart:async';

import 'package:logging/logging.dart';
import 'package:selene/selene.dart' as discord;

void main() {
  runBot();
}

Future runBot() async {
  // Create our client instance
  var client = new discord.Client.create();

  // Listen for log events
  Logger.root.onRecord.listen((LogRecord record) {
    print('[${record.loggerName}] ${record.level.name}: ${record.time}: ${record
        .message}');
  });

  // Listen to the message created event
  client.dispatcher.onMessageCreate.listen((discord.Message message) async {
    if (message.content == '!ping') {
      // Pong
      await message.channel.sendMessage(
          content:
              'Pong!'); // sendMessage takes either content, embed or both. At least one must be supplied.
    }

    if (message.content == '!whoareyou' || message.content == '!bot') {
      var bot = client.cache.self; // Get the client's current user
      // Create an embed
      var embed = new discord.EmbedBuilder();
      embed.author = new discord.EmbedAuthorBuilder.fromUser(
          bot); // Fill in properties from user
      embed.description =
          "Hello there! I am ${bot.username}#${bot.discriminator}!";
      await message.channel
          .sendMessage(embed: embed.build()); // Construct embed
    }
  });

  // Initiate WebSocket connection
  await client.start();

  // Login and authorize
  await client.login(
    'MyToken', /* type: 'Bot' -- This parameter is optional and defaults to Bot. */
  );

  // Client will automatically block the thread
}
0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Predictable Dart bindings for the Discord API.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

logging, w_transport

More

Packages that depend on selene