コード例 #1
0
        /// <summary>
        /// Sends a paginated message with buttons.
        /// </summary>
        /// <param name="channel">The channel to send it on.</param>
        /// <param name="user">User to give control.</param>
        /// <param name="pages">The pages.</param>
        /// <param name="buttons">Pagination buttons (pass null to use buttons defined in <see cref="InteractivityConfiguration"/>).</param>
        /// <param name="behaviour">Pagination behaviour.</param>
        /// <param name="deletion">Deletion behaviour</param>
        /// <param name="token">A custom cancellation token that can be cancelled at any point.</param>
        public async Task SendPaginatedMessageAsync(
            DiscordChannel channel, DiscordUser user, IEnumerable <Page> pages, PaginationButtons buttons,
            PaginationBehaviour?behaviour = default, ButtonPaginationBehavior?deletion = default, CancellationToken token = default)
        {
            var bhv = behaviour ?? this.Config.PaginationBehaviour;
            var del = deletion ?? this.Config.ButtonBehavior;
            var bts = buttons ?? this.Config.PaginationButtons;

            var builder = new DiscordMessageBuilder()
                          .WithContent(pages.First().Content)
                          .WithEmbed(pages.First().Embed);

            var message = await builder.SendAsync(channel).ConfigureAwait(false);

            var req = new ButtonPaginationRequest(message, user, bhv, del, bts, pages.ToArray(), token);

            await builder // We *COULD* just construct a req with a null message and grab the buttons from that, but eh. //
            .AddComponents(await req.GetButtonsAsync().ConfigureAwait(false))
            .ModifyAsync(message).ConfigureAwait(false);

            await this._compPaginator.DoPaginationAsync(req).ConfigureAwait(false);
        }
コード例 #2
0
 /// <summary>
 /// Sends a new paginated message with buttons.
 /// </summary>
 /// <param name="channel">Target channel.</param>
 /// <param name="user">The user that'll be able to control the pages.</param>
 /// <param name="pages">A collection of <see cref="Page"/> to display.</param>
 /// <param name="buttons">Pagination buttons (leave null to default to ones on configuration).</param>
 /// <param name="behaviour">Pagination behaviour.</param>
 /// <param name="deletion">Deletion behaviour</param>
 /// <param name="timeoutoverride">Override timeout period.</param>
 /// <exception cref="InvalidOperationException">Thrown if interactivity is not enabled for the client associated with the channel.</exception>
 public static Task SendPaginatedMessageAsync(this DiscordChannel channel, DiscordUser user, IEnumerable <Page> pages, PaginationButtons buttons, TimeSpan?timeoutoverride, PaginationBehaviour?behaviour = default, ButtonPaginationBehavior?deletion = default)
 => GetInteractivity(channel).SendPaginatedMessageAsync(channel, user, pages, buttons, timeoutoverride, behaviour, deletion);
コード例 #3
0
 /// <summary>
 /// Sends a new paginated message with buttons.
 /// </summary>
 /// <param name="channel">Target channel.</param>
 /// <param name="user">The user that'll be able to control the pages.</param>
 /// <param name="pages">A collection of <see cref="Page"/> to display.</param>
 /// <param name="buttons">Pagination buttons (leave null to default to ones on configuration).</param>
 /// <param name="behaviour">Pagination behaviour.</param>
 /// <param name="deletion">Deletion behaviour</param>
 /// <param name="token">A custom cancellation token that can be cancelled at any point.</param>
 /// <exception cref="InvalidOperationException">Thrown if interactivity is not enabled for the client associated with the channel.</exception>
 public static Task SendPaginatedMessageAsync(this DiscordChannel channel, DiscordUser user, IEnumerable <Page> pages, PaginationButtons buttons, PaginationBehaviour?behaviour = default, ButtonPaginationBehavior?deletion = default, CancellationToken token = default)
 => GetInteractivity(channel).SendPaginatedMessageAsync(channel, user, pages, buttons, behaviour, deletion, token);
コード例 #4
0
 /// <summary>
 /// Sends a paginated message in response to an interaction.
 /// <para>
 /// <b>Pass the interaction directly. Interactivity will ACK it.</b>
 /// </para>
 /// </summary>
 /// <param name="interaction">The interaction to create a response to.</param>
 /// <param name="ephemeral">Whether the response should be ephemeral.</param>
 /// <param name="user">The user to listen for button presses from.</param>
 /// <param name="pages">The pages to paginate.</param>
 /// <param name="buttons">Optional: custom buttons</param>
 /// <param name="behaviour">Pagination behaviour.</param>
 /// <param name="deletion">Deletion behaviour</param>
 /// <param name="token">A custom cancellation token that can be cancelled at any point.</param>
 /// <param name="asEditResponse">If the response as edit of previous response.</param>
 public static Task SendPaginatedResponseAsync(this DiscordInteraction interaction, bool ephemeral, DiscordUser user, IEnumerable <Page> pages, PaginationButtons buttons = null, PaginationBehaviour?behaviour = default, ButtonPaginationBehavior?deletion = default, CancellationToken token = default, bool asEditResponse = false)
 => ChannelExtensions.GetInteractivity(interaction.Channel).SendPaginatedResponseAsync(interaction, ephemeral, user, pages, buttons, behaviour, deletion, token, asEditResponse);