Giter VIP home page Giter VIP logo

nyxx's Introduction

nyxx

Discord pub documentation

A complete, robust and efficient wrapper around Discord's API for bots & applications.

To get started using nyxx, follow our getting started guide to write your first bot.

If you're already familiar with Discord's API, here's a quick example to get you started:

import 'package:nyxx/nyxx.dart';

void main() async {
  final client = await Nyxx.connectGateway('<TOKEN>', GatewayIntents.allUnprivileged);

  final botUser = await client.users.fetchCurrentUser();

  client.onMessageCreate.listen((event) async {
    if (event.mentions.contains(botUser)) {
      await event.message.channel.sendMessage(MessageBuilder(
        content: 'You mentioned me!',
        replyId: event.message.id,
      ));
    }
  });
}

Other nyxx packages

  • nyxx_commands: A command framework for handling both simple & complex commands.
  • nyxx_extensions: Pagination, emoji utilities and other miscellaneous helpers for developing bots using nyxx.
  • nyxx_lavalink: Lavalink support for playing audio in voice channels.

More examples

  • More examples can be found in our GitHub repository here.
  • Running on Dart is a complete example of a bot written with nyxx.

Additional documentation & help

The API documentation for the latest stable version can be found on pub.

Tutorials and wiki articles are hosted here, as well as API documentation for development versions from GitHub.

Our Discord server is where you can get help for any nyxx packages, as well as release announcements and discussions about the library.

Discord's API documentation details what nyxx implements & provides more detailed explanations of certain topics.

The unofficial guild for Discord Bot developers. To get help with nyxx check #dart_nyxx channel.

The dartdocs page will always have the documentation for the latest release.

Contributing to Nyxx

Read the contributing document

Credits

  • Thanks to Hackzzila's for nyx, the original project nyxx was forked from.

nyxx's People

Contributors

abalabahaha avatar abitofevrything avatar alexandre2006 avatar alvaroms25 avatar benny- avatar coocoofroggy avatar hackzzila avatar harryet avatar hexaclue avatar l7ssha avatar lco4edb2 avatar lewdcario avatar luavolk avatar matanlurey avatar mcausc78 avatar memikri avatar mogyuchi avatar n3oney avatar ndso avatar one-nub avatar priyanuj-gogoi avatar quinchs avatar rapougnac avatar rgbcube avatar siongsng avatar slayerornstein avatar sushantchandla avatar v3ntus avatar wasseresser avatar winsuk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

nyxx's Issues

Bot disconnects itself after a while

Hey there, it's been a while.

I'm having issues with the bot disconnecting itself for no reason after some time of inactivity.
I'm currently running it inside a tmux session on a dedicated server on Debian 8 but the same issue occurs with Docker.

These are the only logs I've got for the bot, and as you can see it's supposed to have been running for 12 days.

▶ dart bin/main.dart
[FINE]  {CommandsFramework} - 3.10.2018 15:12:45:734 -- Command [mp] has been registered
[FINE]  {CommandsFramework} - 3.10.2018 15:12:45:745 -- Command [game] has been registered
[FINE]  {CommandsFramework} - 3.10.2018 15:12:45:746 -- Command [player] has been registered
[FINE]  {CommandsFramework} - 3.10.2018 15:12:45:747 -- Command [update] has been registered
[FINE]  {CommandsFramework} - 3.10.2018 15:12:45:748 -- Command [doodle] has been registered
[INFO]  {Client} - 3.10.2018 15:12:47:125 -- Connected and ready!
Ready!

However it's unresponsive to commands and is logged off

image

Do you have any idea or suggestion?

Library status

Hi, I like your library, but because it says "build failing" and the updates are not newest, I have a question: is this library managed and stable?

Thanks a lot!

Support for searching members via websocket

Support for searching guild members via websocket should be supported alongside with http api counterpart.
First part of changes needed to implement arrived with a831b20.

  • Add event for member chunks
  • Implement interface to fetch members via websocket

voice-example Error WebSocketException

I tried to run voice-example and I'm getting this error:

WebSocketException (WebSocketException: SocketException: OS Error: remote host refused connection.
, errno = 1225, address = 127.0.0.1, port = 60609)

Trying to debug, I've noticed it begins here and goes all the way to here. When it tries to do transport.WebSocket.connect(...) the error happens.

Can u guys help?

Thanks in advance.

Incompatible with Dart >=2.0.0

Hey there!
I've been trying to use this lib for a simple test project but had the following issue trying to install it:

[discord_dart] pub get
Resolving dependencies...
The current Dart SDK version is 2.0.0.

Because nyxx >=0.24.0 depends on w_transport >=1.0.1 which requires SDK version <2.0.0, nyxx >=0.24.0 is forbidden.
So, because discord_dart depends on nyxx 0.24.0, version solving failed.
exit code 1

nyxx is the sole dependency I've got in my pubspec.yml.

I've just checked and the w_transport package (even in its 3.2.6 version) requires

environment:
    sdk: ">=1.14.0 <2.0.0"

so this issue is here. Do you have any plan to use something else?

(CommandsFramework) ERROR: NoSuchMethodError: The getter 'bot' was called on null.

Hello! I'm having the following issue when issuing the help (with !help) command:
I've got 5 commands registered with the command module.

[SEVERE]  {Client} - 11.9.2018 19:30:30:784 -- ERROR: NoSuchMethodError: The getter 'bot' was called on null.
Receiver: null
Tried calling: bot 
 #0      Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:46:5)
#1      new CommandsFramework.<anonymous closure>.<anonymous closure> (file:///home/outpox/.pub-cache/git/nyxx-038696e916c7d5096781ff2fdaf43c77e56076e9/lib/src/commands/CommandsFramework.dart:105:44)
#2      _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#3      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#4      _DelayedData.perform (dart:async/stream_impl.dart:584:14)
#5      _StreamImplEvents.handleNext (dart:async/stream_impl.dart:700:11)
#6      _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:660:7)
#7      _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#8      _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#9      _Timer._runTimers (dart:isolate/runtime/libtimer_impl.dart:391:30)
#10     _Timer._handleMessage (dart:isolate/runtime/libtimer_impl.dart:416:5)
#11     _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)

The issue is in CommandsFramework.dart:

_client.onReady.listen((_) {
      _client.onMessage.listen((MessageEvent e) {
        if (ignoreBots && e.message.author.bot) return; // Here
        if (!e.message.content.startsWith(prefix)) return;

        Future.microtask(() => _dispatch(e));
      });
    });

This is odd because I've put a break point on the line 105 and when inspecting the MessageEvent e variable, author and bot are correctly set.

The error also happens when messaging the bot directly (in private message).
I'm up to date with the development branch.

Parse commands arguments

Hey there (it's me again),

I have taken the time to read a good part of the code base and couldn't find this: is it possible to only get the arguments passed to a command?

!ping this is a test

expected:

print(this.message.arguments) // String "this is a test"

The way I see it would be by extending the Message class in order to add an argument property for example. Although that would require to get the command prefix as well as the command itself. What are your thoughts about this?

High memory usage

Now nyxx uses about ~350 MB of memory for 5 guilds with 30k of members.

Things that needs improvement:

  • Event handlers
  • Object constructors

EDIT: Lowered memory usage by ~100 MB

(GuildEmoji) ERROR: NoSuchMethodError: The method '[]' was called on null.

Hey there! I've faced this issue on both the backend_rework and the development branches. It doesn't happen on every server but I couldn't tell the difference. Here's the stack trace:

[SEVERE]  {Client} - 5.9.2018 23:45:36:204 -- ERROR: NoSuchMethodError: The method '[]' was called on null.
Receiver: null
Tried calling: [](Instance of 'Snowflake') 
 #0      Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:46:5)
#1      new GuildEmoji._new.<anonymous closure> (file:///home/outpox/.pub-cache/git/nyxx-eed68e5347a35aa1853d83a83eb83197a7cfb63d/lib/src/nyxx/objects/message/GuildEmoji.dart:41:52)
#2      List.forEach (dart:core/runtime/libgrowable_array.dart:274:8)
#3      new GuildEmoji._new (file:///home/outpox/.pub-cache/git/nyxx-eed68e5347a35aa1853d83a83eb83197a7cfb63d/lib/src/nyxx/objects/message/GuildEmoji.dart:40:20)
#4      new Guild._new.<anonymous closure> (file:///home/outpox/.pub-cache/git/nyxx-eed68e5347a35aa1853d83a83eb83197a7cfb63d/lib/src/nyxx/objects/guild/Guild.dart:111:20)
#5      List.forEach (dart:core/runtime/libgrowable_array.dart:274:8)
#6      new Guild._new (file:///home/outpox/.pub-cache/git/nyxx-eed68e5347a35aa1853d83a83eb83197a7cfb63d/lib/src/nyxx/objects/guild/Guild.dart:110:21)
#7      new GuildCreateEvent._new (file:///home/outpox/.pub-cache/git/nyxx-eed68e5347a35aa1853d83a83eb83197a7cfb63d/lib/src/nyxx/events/GuildCreateEvent.dart:10:15)
#8      Shard._handleMsg (file:///home/outpox/.pub-cache/git/nyxx-eed68e5347a35aa1853d83a83eb83197a7cfb63d/lib/src/nyxx/objects/Shard.dart:247:30)
<asynchronous suspension>
#9      Shard._connect.<anonymous closure>.<anonymous closure> (file:///home/outpox/.pub-cache/git/nyxx-eed68e5347a35aa1853d83a83eb83197a7cfb63d/lib/src/nyxx/objects/Shard.dart:77:20)
<asynchronous suspension>
#10     _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#11     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#12     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#13     _SyncStreamController._sendData (dart:async/stream_controller.dart:763:19)
#14     _StreamController._add (dart:async/stream_controller.dart:639:7)
#15     _StreamController.add (dart:async/stream_controller.dart:585:5)
#16     new _WebSocketImpl._fromSocket.<anonymous closure> (dart:_http/websocket_impl.dart:1128:21)
#17     _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#18     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#19     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#20     _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:68:11)
#21     _EventSinkWrapper.add (dart:async/stream_transformers.dart:15:11)
#22     _WebSocketProtocolTransformer._messageFrameEnd (dart:_http/websocket_impl.dart:337:22)
#23     _WebSocketProtocolTransformer.add (dart:_http/websocket_impl.dart:229:46)
#24     _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:120:24)
#25     _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#26     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#27     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#28     _SyncStreamController._sendData (dart:async/stream_controller.dart:763:19)
#29     _StreamController._add (dart:async/stream_controller.dart:639:7)
#30     _StreamController.add (dart:async/stream_controller.dart:585:5)
#31     _Socket._onData (dart:io/runtime/binsocket_patch.dart:1714:41)
#32     _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#33     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#34     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#35     _SyncStreamController._sendData (dart:async/stream_controller.dart:763:19)
#36     _StreamController._add (dart:async/stream_controller.dart:639:7)
#37     _StreamController.add (dart:async/stream_controller.dart:585:5)
#38     _RawSecureSocket._sendReadEvent (dart:io/secure_socket.dart:1003:19)
#39     Timer._createTimer.<anonymous closure> (dart:async/runtime/libtimer_patch.dart:21:15)
#40     _Timer._runTimers (dart:isolate/runtime/libtimer_impl.dart:382:19)
#41     _Timer._handleMessage (dart:isolate/runtime/libtimer_impl.dart:416:5)
#42     _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)

My main.dart :

import 'package:nyxx/nyxx.dart' as discord;
import 'package:dotenv/dotenv.dart';

main(List<String> arguments) async {
  // Load dotenv
  load();

  DoodleParser dp = DoodleParser("c6a4bi6inz4dmypa");
  await dp.loadData();

  discord.Nyxx bot = new discord.Nyxx(env["DISCORD_KEY"]);
  bot.onReady.listen((discord.ReadyEvent e) {
    print('Ready!');
  });
}

I believe this is because in lib/src/nyxx/objects/message/GuildEmoji.dart (L.41)

    if (raw['roles'] != null) {
      this.rolesIds = List();

      raw['roles'].forEach(
          (o) => this.rolesIds.add(this.guild.roles[Snowflake(o as String)]));
}

this.guild.roles is null. I don't know the Discord API enough to understand what could be the cause for this.

cant get members on ready

I cant seem to get a guilds members onReady anymore. The cache only has 2-3 users.

I tried changing forceFetchMembers and cacheMembers but that doesnt change anything either.

Am i missing something or is there really no way to just request all members?

Infinite typing in DMs

Using the command framework, when declaring the command, if the boolean typing is set to true, and a restriction is added to prevent the command from running in DMs, if you run the command in a DM anyways the bot will start typing indefinitely.

Example code: (even something as simple as this does it)

@Restrict(requiredContext: ContextType.guild)
@Command("error", typing: true)
Future<void> error(CommandContext ctx) async {
  ctx.message.reply(content: "This won't send in a DM; but the bot will type");
}

CommandFramework improperly responds when a stream is passed

A stream is allowed to be set but when you set it, the code looks to ignore it and rather would raise an error saying that a framework cannot be made without a prefix - specifically the bit seen below

client.onReady.listen((_) {
    if (prefix == null && stream == null) {
      prefix = client.self.mention;
      stream = client.onSelfMention;
    } else if (stream == null && prefix != null)
      stream = client.onMessageReceived;
    else {
      _logger.severe("CANNOT CREATE FRAMEWORK WITHOUT PREFIX");
      exit(1);
    }

I dunno how exactly the intended behaviour would be where if a stream was given and a prefix was not given. Logically I assume you would just inherit the prefix to be the bot's mention and the stream to be the given stream.

If that's the intended path of what you want to do, the final else could be changed to

else if (stream != null && prefix == null) 
        prefix = client.self.mention; 

instead and not stop execution because in another scenario all that would be left is stream != null && prefix != null which would be the intended action in my scenario (because I want stream & prefix to be custom)

(also as always I'm on the rewrite_modular branch)

Improvement of audit logs

Audit logs are actually very badly written. Have rewrite all stuff connected with auditlogs.

  • Implement custom deserializing for each change type
  • Cache (?)
  • Implement methods to improve working with audit logs
  • Remove all unneeded stuff

CommandContext nextMessages() not receiving messages

Whenever I try to use nextMessages(), no messages seem to be received through the stream. Take the following code.

main() async {
  final bot = NyxxVm(TOKEN);
  CommandsFramework(bot, prefix: "s!")
    ..discoverCommands();

  [other code]
}

@Command("login")
Future<void> login(CommandContext ctx) async {
  print("login start");
  final loginInfo = ctx.nextMessages(3);
  await for (final value in loginInfo) {
    print(value.message.content);
  }
  ctx.reply(content: "abc");

  [other code]
}

Ideally, after sending "s!login", this would print "login start" and the next three messages I send the bot in the same channel to the console, then reply with "abc". However, only "login start" is printed, and "abc" is not sent back after sending three messages to the bot.

Can't send DM to user

When trying to send a DM to a user i get

Exception has occurred.
StateError (Bad state: No element)

Relevant code

e.guild.members[discord.Snowflake(id)].send(content: msg);

(User) ERROR: Invalid argument(s)

Hello! I'm having an issue when calling print with a Member property:

// Map<Snowflake, Member> discordMembers;
this.discordMembers.forEach((id, member) => print(member));

discordMembers is retrieved from within the context of a command with this.guild.members.

[SEVERE]  {Client} - 10.9.2018 14:8:25:871 -- ERROR: Invalid argument(s) 
 #0      _StringBase._interpolate (dart:core/runtime/libstring_patch.dart:823:9)
#1      User.mention (file:///home/guillaume/.pub-cache/git/nyxx-87087a8e48300c0f24289998dcd3c66bda1142ad/lib/src/nyxx/objects/guild/User.dart:21:40)
#2      User.toString (file:///home/guillaume/.pub-cache/git/nyxx-87087a8e48300c0f24289998dcd3c66bda1142ad/lib/src/nyxx/objects/guild/User.dart:95:29)
#3      Member.toString (file:///home/guillaume/.pub-cache/git/nyxx-87087a8e48300c0f24289998dcd3c66bda1142ad/lib/src/nyxx/objects/guild/Member.dart:138:30)
#4      _StringBase._interpolateSingle (dart:core/runtime/libstring_patch.dart:799:17)
#5      print (dart:core/print.dart:9:26)
#6      new DiscordUserFromDoodle.<anonymous closure> (package:DCGB/src/DiscordUserFromDoodle.dart:14:49)
#7      __InternalLinkedHashMap&_HashVMBase&MapMixin&_LinkedHashMapMixin.forEach (dart:collection/runtime/libcompact_hash.dart:363:8)
#8      new DiscordUserFromDoodle (package:DCGB/src/DiscordUserFromDoodle.dart:14:25)
#9      DoodleParser.messageUsersOfGame.<anonymous closure> (package:DCGB/src/doodle/parser.dart:118:19)
#10     List.forEach (dart:core/runtime/libgrowable_array.dart:274:8)
#11     DoodleParser.messageUsersOfGame (package:DCGB/src/doodle/parser.dart:117:17)
#12     MPCommand.run (file:///home/guillaume/perso/projects/discord_dart/bin/main.dart:71:9)
<asynchronous suspension>
#13     _LocalInstanceMirror._invoke (dart:mirrors/runtime/libmirrors_impl.dart:327:37)
#14     _LocalInstanceMirror.invoke (dart:mirrors/runtime/libmirrors_impl.dart:323:25)
#15     CommandsFramework._dispatch (file:///home/guillaume/.pub-cache/git/nyxx-87087a8e48300c0f24289998dcd3c66bda1142ad/lib/src/commands/CommandsFramework.dart:419:28)
<asynchronous suspension>
#16     new CommandsFramework.<anonymous closure>.<anonymous closure>.<anonymous closure> (file:///home/guillaume/.pub-cache/git/nyxx-87087a8e48300c0f24289998dcd3c66bda1142ad/lib/src/commands/CommandsFramework.dart:108:32)
#17     new Future.microtask.<anonymous closure> (dart:async/future.dart:202:37)
#18     _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#19     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#20     _Timer._runTimers (dart:isolate/runtime/libtimer_impl.dart:391:30)
#21     _Timer._handleMessage (dart:isolate/runtime/libtimer_impl.dart:416:5)
#22     _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)

I believe it comes from the mention getter in User.dart L.21 with this.id being null which is weird.

Bad state: Cannot add event after closing

How to properly dispose bot?
I'm using these code:

await _tmpBot.onReady.drain();
await _tmpBot.close();
await _tmpBot.dispose();

And after few minutes I'm getting few hundreds of these exceptions

Bad state: Cannot add event after closing
#0      _StreamController.add (dart:async/stream_controller.dart:585:24)
#1      CommonWebSocket.add (package:w_transport/src/web_socket/common/web_socket.dart:124:15)
#2      Shard.send (file:///home/kuba/flutter/flutter/.pub-cache/git/nyxx-flutter-892c2603f34df169771ba9bc3273b8d2b7405485/lib/src/nyxx/Shard.dart:115:18)
#3      Shard._heartbeat (file:///home/kuba/flutter/flutter/.pub-cache/git/nyxx-flutter-892c2603f34df169771ba9bc3273b8d2b7405485/lib/src/nyxx/Shard.dart:121:10)
#4      Shard._handleMsg.<anonymous closure> (file:///home/kuba/flutter/flutter/.pub-cache/git/nyxx-flutter-892c2603f34df169771ba9bc3273b8d2b7405485/lib/src/nyxx/Shard.dart:158:31)
#5      _rootRunUnary (dart:async/zone.dart:1132:38)
#6      _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#7      _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
#8      _CustomZone.bindUnaryCallbackGuarded.<anonymous closure> (dart:async/zone.dart:968:26)
#9      _rootRunUnary (dart:async/zone.dart:1136:13)
#10     _CustomZone.runUnary (da

NoSuchMethodError when sending embed to a DM.

I've only seen it when sending an embed to a DM channel, regular discord channels don't have this issue. (This isn't a bot breaking bug though - the embed still shows up in the DM for the user).
Using the rewrite_modular branch and Dart 2.7.0.

Traceback from Logging

[2020-02-07 22:32:14.817696] �[31m[SEVERE] [Client]�[0m: ERROR: NoSuchMethodError: The method '[]' was called on null.
Receiver: null
Tried calling: []("id") 
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
#1      new Message._new (package:nyxx/src/objects/message/Message.dart:98:57)
#2      new MessageUpdateEvent._new (package:nyxx/src/events/MessageEvents.dart:171:31)
#3      Shard._handleMsg (package:nyxx/src/Shard.dart:271:40)
#4      Shard._connect.<anonymous closure>.<anonymous closure> (package:nyxx/src/Shard.dart:91:18)
#5      _RootZone.runUnaryGuarded (dart:async/zone.dart:1316:10)
#6      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:338:11)
#7      _DelayedData.perform (dart:async/stream_impl.dart:593:14)
#8      _StreamImplEvents.handleNext (dart:async/stream_impl.dart:709:11)
#9      _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:669:7)
#10     _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
#11     _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)
#12     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:393:30)
#13     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:418:5)
#14     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)

Sample code:

@Command("dm_error")
Future<void> dmError(CommandContext ctx) async {
  DMChannel authorDM = await ctx.author.dmChannel;

  var embed = EmbedBuilder();
  embed.title = "test";

  //Both instances cause the NoSuchMethodError
  if(ctx.channel is DMChannel) {
    await ctx.message.reply(embed: embed);
  } else {
    await authorDM.send(embed: embed);
  }
}

Use of singleton bot within library

Nyxx is object oriented but different parts of the library all reference the singleton Nyxx bot instance. This leads to problems when creating multiple bots.

For this issue to be resolved, the internal library no longer needs to reference this Nyxx singleton.

Issue with embeds

In commit 4532f5d, embeds without fields will not send. The error is Bad state: No element. If I had to guess, at some point you are trying to check field values without verifying they exist (?). Thanks :)

Logging will be broken by dart-lang/logging#71

I've recently made a change (dart-lang/logging#71) that affects the behavior of Logger.detached from package:logging. This change expected to be included in logging 0.11.4.

This change in behavior should not affect most packages, but it appears that it will break logging in the nyxx package.

The recommended fix is to set Logger.level and Logger.onRecord on the detached Logger itself instead of on Logger.root. (In general, libraries should leave responsibility for configuring Logger.root to the application.)

Web support

Nyx supported web. This issue is about adding support for web environment back into Nyxx.

Don't always rely on cache

Due new feature of gateway called intents caches cant be always populated with data. Also when user disables cache, there wont be data in many cases available in events. Library should deserialize objects if no cache is available

Permission checks

Nyxx should check if bot has needed permissions for given action before sending request.

  • Permissions checks in JDA

Expose http module to user

Due removal of Downloadable interface and lack of other way to interact with bots http client. Some of APIs should be exposed to user. It will allow to perform request via bots backend without using w_transport 'externally'.

Redesign of CI setup

Current CI setup should be redesigned due nyxx changes to include:

  • tests for all packages
  • automatic docs deployment
  • testing against stable and dev version of dart
  • compiling tests to native on stable version of dart
  • checking if code is formatted via dartfmt

Shard [0] disconnected. Error code: [1001]

Hey there, I'm having the following error:

[FINE]  {CommandsFramework} - 18.10.2018 9:23:6:961 -- Command [mp] has been registered
[FINE]  {CommandsFramework} - 18.10.2018 9:23:6:972 -- Command [game] has been registered
[FINE]  {CommandsFramework} - 18.10.2018 9:23:6:973 -- Command [player] has been registered
[FINE]  {CommandsFramework} - 18.10.2018 9:23:6:974 -- Command [update] has been registered
[FINE]  {CommandsFramework} - 18.10.2018 9:23:6:975 -- Command [doodle] has been registered
false, true
[INFO]  {Websocket} - 18.10.2018 9:23:7:861 -- Shard [0] connected
[INFO]  {Client} - 18.10.2018 9:23:8:208 -- Connected and ready!
Ready!
UNKNOWN OPCODE: {"t":"GUILD_INTEGRATIONS_UPDATE","s":195,"op":0,"d":{"guild_id":"450704289141358607"}}
UNKNOWN OPCODE: {"t":"GUILD_INTEGRATIONS_UPDATE","s":629,"op":0,"d":{"guild_id":"450704289141358607"}}
UNKNOWN OPCODE: {"t":"GUILD_INTEGRATIONS_UPDATE","s":882,"op":0,"d":{"guild_id":"450704289141358607"}}
UNKNOWN OPCODE: {"t":"GUILD_INTEGRATIONS_UPDATE","s":1138,"op":0,"d":{"guild_id":"450704289141358607"}}
UNKNOWN OPCODE: {"t":"GUILD_INTEGRATIONS_UPDATE","s":1441,"op":0,"d":{"guild_id":"450704289141358607"}}
UNKNOWN OPCODE: {"t":"GUILD_INTEGRATIONS_UPDATE","s":1857,"op":0,"d":{"guild_id":"450704289141358607"}}
UNKNOWN OPCODE: {"t":"GUILD_INTEGRATIONS_UPDATE","s":2223,"op":0,"d":{"guild_id":"450704289141358607"}}
UNKNOWN OPCODE: {"t":"GUILD_INTEGRATIONS_UPDATE","s":2654,"op":0,"d":{"guild_id":"450704289141358607"}}
UNKNOWN OPCODE: {"t":"GUILD_INTEGRATIONS_UPDATE","s":3247,"op":0,"d":{"guild_id":"450704289141358607"}}
UNKNOWN OPCODE: {"t":"GUILD_INTEGRATIONS_UPDATE","s":3770,"op":0,"d":{"guild_id":"450704289141358607"}}
UNKNOWN OPCODE: {"t":"GUILD_INTEGRATIONS_UPDATE","s":4364,"op":0,"d":{"guild_id":"450704289141358607"}}
UNKNOWN OPCODE: {"t":"GUILD_INTEGRATIONS_UPDATE","s":4896,"op":0,"d":{"guild_id":"450704289141358607"}}
UNKNOWN OPCODE: {"t":"GUILD_INTEGRATIONS_UPDATE","s":5346,"op":0,"d":{"guild_id":"450704289141358607"}}
UNKNOWN OPCODE: {"t":"GUILD_INTEGRATIONS_UPDATE","s":5914,"op":0,"d":{"guild_id":"450704289141358607"}}
UNKNOWN OPCODE: {"t":"GUILD_INTEGRATIONS_UPDATE","s":6398,"op":0,"d":{"guild_id":"450704289141358607"}}
UNKNOWN OPCODE: {"t":"GUILD_INTEGRATIONS_UPDATE","s":6701,"op":0,"d":{"guild_id":"450704289141358607"}}
UNKNOWN OPCODE: {"t":"GUILD_INTEGRATIONS_UPDATE","s":6845,"op":0,"d":{"guild_id":"450704289141358607"}}
UNKNOWN OPCODE: {"t":"GUILD_INTEGRATIONS_UPDATE","s":7081,"op":0,"d":{"guild_id":"450704289141358607"}}
UNKNOWN OPCODE: {"t":"GUILD_INTEGRATIONS_UPDATE","s":7166,"op":0,"d":{"guild_id":"450704289141358607"}}
UNKNOWN OPCODE: {"t":"GUILD_INTEGRATIONS_UPDATE","s":7264,"op":0,"d":{"guild_id":"450704289141358607"}}
[SEVERE]  {Websocket} - 19.10.2018 6:14:22:837 -- Shard [0] disconnected. Error code: [1001] | Error message: []
[SEVERE]  {Websocket} - 19.10.2018 6:14:22:842 -- SHARD [0] DISCONNECTED. Trying to reconnect...
[SEVERE]  {Websocket} - 19.10.2018 6:14:24:844 -- SHARD [0] DISCONNECTED. Trying to reconnect...
[SEVERE]  {Websocket} - 19.10.2018 6:14:26:846 -- SHARD [0] DISCONNECTED. Trying to reconnect...
[SEVERE]  {Websocket} - 19.10.2018 6:14:28:847 -- SHARD [0] DISCONNECTED. Trying to reconnect...
[SEVERE]  {Websocket} - 19.10.2018 6:14:30:848 -- SHARD [0] DISCONNECTED. Trying to reconnect...
[SEVERE]  {Websocket} - 19.10.2018 6:14:32:849 -- SHARD [0] DISCONNECTED. Trying to reconnect...
[SEVERE]  {Websocket} - 19.10.2018 6:14:34:850 -- SHARD [0] DISCONNECTED. Trying to reconnect...
[SEVERE]  {Websocket} - 19.10.2018 6:14:36:851 -- SHARD [0] DISCONNECTED. Trying to reconnect...
[...] and it goes on

I'm currently running the bot in tmux.
If you need more information, please ask.

Spoilers

TODO:

  • Helper method for attaching files as spoilers
  • Helper for creating text spoilers
  • Parsing spoilers in message

Rewrite Http backend

HTTP back end should be rewritten due confusing code which is hard to read, work and maintain. It should be replaced with something more lightweight

Exponential backoff

At the moment Nyxx reconnects quickly after failures.

I'd suggest to change this to a exponential back-off algorithm so it doesn't waste too much resources if it gets into a failure loop.

As it stands I received an email from discord; they had to reset my bot token after 1000 connection attempts while I left the bot on overnight.

I can't use example

I can't use NyxxVm.
And I use Nyxx('MY_DISCORD_TOKEN');
But returned
NotSetupError: Token is null or empty or bot isn't set properly!

Unknown opcode was emitted to the console

Console log:

[2018-10-30 19:14:13.627] [INFO] [Websocket]: Shard [0] connected
[2018-10-30 19:14:13.882] [INFO] [Client]: Connected and ready!
UNKNOWN OPCODE: {"t":"PRESENCES_REPLACE","s":10,"op":0,"d":[]}

Command execution debug regression

Hey there,

Following your recommandation I've updated my commands declaration.
When using the following format:

@command.Module("player")
class PlayerCommand extends command.CommandContext {
  @command.Command(main: true)
  @command.Help("player", usage: "!gb_player playerName")
  Future run(@command.Remainder() String argument) async {
    if (argument == "") {
      return await reply(content: "Merci de préciser un joueur");
    }
    await reply(content: gdp.getGamesForUser(argument));
  }
}

I've got the following logs:

[FINE]  {CommandsFramework} - 16.10.2018 18:56:37:436 -- Command [mp] has been registered
[FINE]  {CommandsFramework} - 16.10.2018 18:56:37:438 -- Command [player] has been registered
[FINE]  {CommandsFramework} - 16.10.2018 18:56:37:438 -- Command [update] has been registered
[FINE]  {CommandsFramework} - 16.10.2018 18:56:37:438 -- Command [doodle] has been registered
[FINE]  {CommandsFramework} - 16.10.2018 18:56:37:438 -- Command [game] has been registered
false, true
[INFO]  {Websocket} - 16.10.2018 18:56:38:208 -- Shard [0] connected
[INFO]  {Client} - 16.10.2018 18:56:38:427 -- Connected and ready!
Ready!
[FINE]  {CommandsFramework} - 16.10.2018 18:56:43:30 -- Command [player] executed

However, with the new suggested format

 @command.Command(name: "player")
 @command.Help("player", usage: "!gb_player playerName")
 Future run(command.CommandContext ctx, @command.Remainder() String argument) async {
   if (argument == "") {
     return await ctx.reply(content: "Merci de préciser un joueur");
   }
   await ctx.reply(content: gdp.getGamesForUser(argument));
 }

when sending a command the log is:

[FINE]  {CommandsFramework} - 16.10.2018 18:56:43:30 -- Command [] executed

The executed command is missing.

(GuildMemberRemoveEvent) ERROR: NoSuchMethodError: The getter 'memberCount' was called on null.

Along the error in #7 I had the following issue as well:

[SEVERE]  {Client} - 6.9.2018 17:8:40:409 -- ERROR: NoSuchMethodError: The getter 'memberCount' was called on null.
Receiver: null
Tried calling: memberCount 
 #0      Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:46:5)
#1      new GuildMemberRemoveEvent._new (file:///root/.pub-cache/git/nyxx-87087a8e48300c0f24289998dcd3c66bda1142ad/lib/src/nyxx/events/GuildMemberRemoveEvent.dart:14:13)
#2      Shard._handleMsg (file:///root/.pub-cache/git/nyxx-87087a8e48300c0f24289998dcd3c66bda1142ad/lib/src/nyxx/objects/Shard.dart:274:36)
<asynchronous suspension>
#3      Shard._connect.<anonymous closure>.<anonymous closure> (file:///root/.pub-cache/git/nyxx-87087a8e48300c0f24289998dcd3c66bda1142ad/lib/src/nyxx/objects/Shard.dart:77:20)
<asynchronous suspension>
#4      _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#5      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#6      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#7      _SyncStreamController._sendData (dart:async/stream_controller.dart:763:19)
#8      _StreamController._add (dart:async/stream_controller.dart:639:7)
#9      _StreamController.add (dart:async/stream_controller.dart:585:5)
#10     new _WebSocketImpl._fromSocket.<anonymous closure> (dart:_http/websocket_impl.dart:1128:21)
#11     _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#12     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#13     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#14     _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:68:11)
#15     _EventSinkWrapper.add (dart:async/stream_transformers.dart:15:11)
#16     _WebSocketProtocolTransformer._messageFrameEnd (dart:_http/websocket_impl.dart:334:22)
#17     _WebSocketProtocolTransformer.add (dart:_http/websocket_impl.dart:229:46)
#18     _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:120:24)
#19     _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#20     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#21     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#22     _SyncStreamController._sendData (dart:async/stream_controller.dart:763:19)
#23     _StreamController._add (dart:async/stream_controller.dart:639:7)
#24     _StreamController.add (dart:async/stream_controller.dart:585:5)
#25     _Socket._onData (dart:io/runtime/binsocket_patch.dart:1714:41)
#26     _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#27     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#28     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#29     _SyncStreamController._sendData (dart:async/stream_controller.dart:763:19)
#30     _StreamController._add (dart:async/stream_controller.dart:639:7)
#31     _StreamController.add (dart:async/stream_controller.dart:585:5)
#32     _RawSecureSocket._sendReadEvent (dart:io/secure_socket.dart:1003:19)
#33     Timer._createTimer.<anonymous closure> (dart:async/runtime/libtimer_patch.dart:21:15)
#34     _Timer._runTimers (dart:isolate/runtime/libtimer_impl.dart:382:19)
#35     _Timer._handleMessage (dart:isolate/runtime/libtimer_impl.dart:416:5)
#36     _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)

BTW I know that this library is under development so I don't know if this issues are helpful to you, let me know ;-)

Replace internal sharding by user managed sharding

At the moment Nyxx has "internal sharding". It makes multiple connections to the discord gateway. But it all operates within the same process and does not help alleviate any problems related to processing power. This internal sharding does not allow Nyxx to process more messages.

This ticket is about replacing the current internal sharding and moving the responsibility to the caller of the library. The bot will have two extra optional parameters. The shard id and the maximum shard number. The user of the library must make sure to start all Nyxx shards.

(RoleDeleteEvent) ERROR: NoSuchMethodError: The getter 'roles' was called on null.

Hey there,
My bot crashed during the night and there was this error in my logs:

[SEVERE]  {Client} - 6.9.2018 17:8:40:401 -- ERROR: NoSuchMethodError: The getter 'roles' was called on null.
Receiver: null
Tried calling: roles 
 #0      Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:46:5)
#1      new RoleDeleteEvent._new (file:///root/.pub-cache/git/nyxx-87087a8e48300c0f24289998dcd3c66bda1142ad/lib/src/nyxx/events/RoleDeleteEvent.dart:12:25)
#2      Shard._handleMsg (file:///root/.pub-cache/git/nyxx-87087a8e48300c0f24289998dcd3c66bda1142ad/lib/src/nyxx/objects/Shard.dart:310:29)
<asynchronous suspension>
#3      Shard._connect.<anonymous closure>.<anonymous closure> (file:///root/.pub-cache/git/nyxx-87087a8e48300c0f24289998dcd3c66bda1142ad/lib/src/nyxx/objects/Shard.dart:77:20)
<asynchronous suspension>
#4      _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#5      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#6      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#7      _SyncStreamController._sendData (dart:async/stream_controller.dart:763:19)
#8      _StreamController._add (dart:async/stream_controller.dart:639:7)
#9      _StreamController.add (dart:async/stream_controller.dart:585:5)
#10     new _WebSocketImpl._fromSocket.<anonymous closure> (dart:_http/websocket_impl.dart:1128:21)
#11     _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#12     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#13     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#14     _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:68:11)
#15     _EventSinkWrapper.add (dart:async/stream_transformers.dart:15:11)
#16     _WebSocketProtocolTransformer._messageFrameEnd (dart:_http/websocket_impl.dart:334:22)
#17     _WebSocketProtocolTransformer.add (dart:_http/websocket_impl.dart:229:46)
#18     _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:120:24)
#19     _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#20     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#21     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#22     _SyncStreamController._sendData (dart:async/stream_controller.dart:763:19)
#23     _StreamController._add (dart:async/stream_controller.dart:639:7)
#24     _StreamController.add (dart:async/stream_controller.dart:585:5)
#25     _Socket._onData (dart:io/runtime/binsocket_patch.dart:1714:41)
#26     _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#27     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#28     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#29     _SyncStreamController._sendData (dart:async/stream_controller.dart:763:19)
#30     _StreamController._add (dart:async/stream_controller.dart:639:7)
#31     _StreamController.add (dart:async/stream_controller.dart:585:5)
#32     _RawSecureSocket._sendReadEvent (dart:io/secure_socket.dart:1003:19)
#33     Timer._createTimer.<anonymous closure> (dart:async/runtime/libtimer_patch.dart:21:15)
#34     _Timer._runTimers (dart:isolate/runtime/libtimer_impl.dart:382:19)
#35     _Timer._handleMessage (dart:isolate/runtime/libtimer_impl.dart:416:5)
#36     _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)

Command framework problems

Hello, I'm having issues with commands in my bot, I wanted to create a command usable by the administrator of the server to delete everything on the server, the problem I'm having is that my for loop inside my command either work and make one iteration before stopping, either do not work at all, or my command simply is not called at all. Working totally randomly. The code :

@Command('deleteall', aliases: ['da'])
Future<void> deleteAll(CommandContext ctx) async {
  Restrict(
    userPermissions: [PermissionsConstants.administrator],
    botPermissions: [PermissionsConstants.administrator]
  );
  
  var arguments = ctx.message.toString().split(' ');
  switch (arguments[1]) {
    case '*':
      var message = await ctx.reply(content: 'En cours');
      for (var value in ctx.guild.channels.values) {
        sleep(const Duration(seconds: 2));
        await value
            .delete(
                auditReason:
                    'Asked by ${ctx.author.username} who executed the command deleteall *')
            .catchError(throw ("PermissionError"));
      }
  }

  for (var role in ctx.guild.roles.values) {
    await role.delete(
        auditReason:
            'Asked by ${ctx.author.username} who executed the command deleteall *');
  }
}

Thanks in advance for the answers.

Enum class enhancement

All "enum classes" like ActivityType or PremiumType should have common super class and field to get real value of enum.

Related to #69

Command Framework redesign

Command Framework is now big maze of code which isn't understandable and maintainable.
Handling command could be rewritten to be similar to current Command Parser, but with more flexibility and features.
Biggest reason to re-do commands is because it depends on dart:mirrors package which is heavy on resources and hard to work with. It also excludes using commands in browser because mirrors aren't supported there.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.