首页 > 解决方案 > DSharp + static void main() 不会加载

问题描述

我想我的主要方法可能需要帮助,每当我尝试加载我的 Discord 机器人时,它都会给我一个未处理的异常,这就是异常的含义:System.ArgumentNullException: 'Type must be a class, which cannot be abstract or static. Parameter name: t'

这是完整的堆栈跟踪:“在 DSharpPlus.CommandsNext.CommandsNextExtension.RegisterCommands(Type t)\r\n at DSharpPlus.CommandsNext.CommandsNextExtension.RegisterCommandsT\r\n at Arthur_Bot.Bot.RunAsync() in C:\Users\bvgof \OneDrive\Documents\Visual Studio 2017\Projects\Arthur-Bot\Arthur-Bot\Bot.cs:line 54\r\n at Arthur_Bot.Program.Main(String[] args) in C:\Users\bvgof\OneDrive \Documents\Visual Studio 2017\Projects\Arthur-Bot\Arthur-Bot\Program.cs:line 8"

程序.cs:

namespace Arthur_Bot
{
    class Program
    {
        public static void Main(string[] args)
        {
            var bot = new Bot();
            bot.RunAsync().GetAwaiter().GetResult();
        }
    }
}

机器人.cs:

using Arthur_Bot.Commands;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.EventArgs;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.IO;
using System.Text;
using System.Threading.Tasks;

namespace Arthur_Bot
{
    public class Bot
    {
        public DiscordClient Client { get; private set; }

        public CommandsNextExtension Commands { get; private set; }

        public async Task RunAsync()
        {
            var json = string.Empty;

            using (var fs = File.OpenRead("config.json"))
            using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
                json = await sr.ReadToEndAsync().ConfigureAwait(false);

            var configJson = JsonConvert.DeserializeObject<ConfigJson>(json);

            var config = new DiscordConfiguration
            {
                Token = configJson.Token,
                TokenType = TokenType.Bot,
                AutoReconnect = true,
                MinimumLogLevel = LogLevel.Debug
            };

            Client = new DiscordClient(config);

            Client.Ready += OnClientReady;

            var commandsConfig = new CommandsNextConfiguration
            {
                StringPrefixes = new string[] { configJson.Prefix },
                EnableMentionPrefix = true,
                EnableDefaultHelp = false,
                EnableDms = false,
                CaseSensitive = true,
                DmHelp = false
            };

            Commands = Client.UseCommandsNext(commandsConfig);

            Commands.RegisterCommands<FunCommands>();
            Commands.RegisterCommands<EconomyCommands>();
            Commands.RegisterCommands<ModeratorCommands>();
            Commands.RegisterCommands<ProfileCommands>();
            Commands.RegisterCommands<HelpCommands>();

            await Client.ConnectAsync();

            await Task.Delay(-1);
        }

        private Task OnClientReady(DiscordClient client, ReadyEventArgs e)
        {
            client = Client;
            return Task.CompletedTask;
        }
    }
}

我不知道发生了什么,我可以帮忙吗?

标签: c#exceptionmaindsharp+

解决方案


推荐阅读