d4n3436 / Fergun.Interactive

An addon that provides interactive functionality to Discord commands.
MIT License
31 stars 5 forks source link

"Object reference not set to an instance of an object" in paaginator message. #3

Closed Paladic closed 3 years ago

Paladic commented 3 years ago

Hi. I recently connected to your addon and am seeing this error. I do not understand why it was caused, although it seems to have done everything as in your example. Even the example doesn't work in the end.

Please, help

        [Command("hello",RunMode = RunMode.Async)]
        public async Task PaginatorAsync()
        {
            var pages = new[] {
                new PageBuilder().WithDescription("Lorem ipsum dolor sit amet, consectetur adipiscing elit."),
                new PageBuilder().WithDescription("Praesent eu est vitae dui sollicitudin volutpat."),
                new PageBuilder().WithDescription("Etiam in ex sed turpis imperdiet viverra id eget nunc."),
                new PageBuilder().WithDescription("Donec eget feugiat nisi. Praesent faucibus malesuada nulla, a vulputate velit eleifend ut.")
            };

            Paginator paginator = new StaticPaginatorBuilder()
                .AddUser(Context.User) // Only allow the user that executed the command to interact with the selection.
                .WithPages(pages) // Set the pages the paginator will use. This is the only required component.
                .Build();

            // Send the paginator to the source channel and wait until it times out after 10 minutes.
            await Interactive.SendPaginatorAsync(paginator, Context.Channel, TimeSpan.FromMinutes(10));

            // Most of the time you won't need the result of the paginator so you can safely discard the task:
            // _ = Interactive.SendPaginatorAsync(paginator, Context.Channel, TimeSpan.FromMinutes(10));
        }

Error: Discord.Commands.CommandException: Error occurred executing "hello" . ---> System.NullReferenceException: Object reference not set to an instance of an object. at Discord_bot.Modules.General.PaginatorAsync() in C:...\Discord bot\Modules\General.cs:line 302 at Discord.Commands.ModuleClassBuilder.<>c__DisplayClass6_0.<g__ExecuteCallback|0>d.MoveNext() --- End of stack trace from previous location --- at Discord.Commands.CommandInfo.ExecuteInternalAsync(ICommandContext context, Object[] args, IServiceProvider services) --- End of inner exception stack trace ---

d4n3436 commented 3 years ago

Hi, you're probably getting a NullReferenceException because Interactive is null. Make sure you're properly setting up the InteractiveService using dependency injection.

Paladic commented 3 years ago

Oh ... sorry, I made a mistake and did not notice, or rather, I thought that it would not affect, sorry again. Instead of

public InteractiveService Interactive { get; set; }

i used

private InteractiveService Interactive { get; set; }

or

private readonly InteractiveService Interactive { get; set; }

again sorry, thanks for helping!