Skip to content

None of the commands in the InteractiveBase class is working #29

Description

@Shirabana

Hi, I've been trying to use this but none of the discord commands in the class seem to work (such as ReplyAsync and NextMessageAsync. All of them throw a Exception thrown: 'System.NullReferenceException' in mscorlib.dll exception when trying to be used. I checked this as the bot never reaches log.Info(response.ToString());.

Here's some of the code I'm using:

Program.cs

_services = new ServiceCollection()
                .AddSingleton(_client)
                .AddSingleton(_commands)
                .AddSingleton<InteractiveService>()
                .BuildServiceProvider();

InteractionClass.cs:

using System;
using System.Threading.Tasks;
using Discord.Commands;
using Discord.Addons.Interactive;

namespace EimiBot2.Modules
{
    public class InteractionClass : InteractiveBase
    {
        private Logger log = new Logger();

        public async Task GetConfirmation(string replyMessage)
        {
            int next = 0;
            while (next < 5)
            {
                await ReplyAsync(replyMessage);
                var response = await NextMessageAsync();
                
                log.Info(response.ToString());

                if (response != null || response.ToString() != "")
                {
                    if (response.ToString().ToLower() == "yes")
                    {
                        _ = new AdminCommands { ReplyStatus = true };
                        next = 10;

                    }
                    else if (response.ToString().ToLower() == "no")
                    {
                        _ = new AdminCommands { ReplyStatus = false };
                        next = 10;
                    }
                    else
                    {
                        await ReplyAsync("Invalid input. Input one more time.");
                        next++;
                    }
                }
            }

            if (next < 10)
            {
                await ReplyAsync("Invalid inputs. Will close the function.");
                _ = new AdminCommands { ReplyStatus = false };
            }
        }
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions