createUserContext method

Future<UserContext> createUserContext(
  1. ApplicationCommandInteraction interaction,
  2. UserCommand command
)

Create a UserContext from an ApplicationCommandInteraction.

interaction is the interaction event that triggered the command and command is the command executed by the event.

Implementation

Future<UserContext> createUserContext(
  ApplicationCommandInteraction interaction,
  UserCommand command,
) async {
  Member? member = interaction.member;
  User user = member?.user ?? interaction.user!;

  final client = interaction.manager.client as NyxxGateway;

  User targetUser = await client.users[interaction.data.targetId!].get();
  Guild? guild = await interaction.guild?.get();

  return UserContext(
    commands: commands,
    client: client,
    interaction: interaction,
    command: command,
    channel: await interaction.channel!.get() as TextChannel,
    member: member,
    user: user,
    guild: guild,
    targetUser: targetUser,
    targetMember: await guild?.members[targetUser.id].get(),
  );
}