createMessageChatContext method

Future<MessageChatContext> createMessageChatContext(
  1. Message message,
  2. StringView contentView,
  3. String prefix
)

Create a MessageChatContext from a Message.

message is the message that triggered the command, contentView is a StringView of the message's content with the prefix already skipped and prefix is the content of the match that was skipped.

Throws a CommandNotFoundException if message did not match any command on commands.

You might also be interested in:

Implementation

Future<MessageChatContext> createMessageChatContext(
  Message message,
  StringView contentView,
  String prefix,
) async {
  ChatCommand command =
      commands.getCommand(contentView) ?? (throw CommandNotFoundException(contentView));

  TextChannel channel = await message.channel.get() as TextChannel;
  User user = message.author as User;

  Guild? guild;
  Member? member;
  if (channel is GuildChannel) {
    guild = await (channel as GuildChannel).guild.get();
    member = await guild.members[user.id].get();
  }

  return MessageChatContext(
    commands: commands,
    guild: guild,
    channel: channel,
    member: member,
    user: user,
    command: command,
    client: message.manager.client as NyxxGateway,
    prefix: prefix,
    message: message,
    rawArguments: contentView.remaining,
  );
}