如何在C#参数1上修复错误cs1503:无法从'system.reflection.assembly'转换为'system.type' [英] How do I fix error cs1503 on C# argument 1: cannot convert from 'system.reflection.assembly' to 'system.type'

查看:2019
本文介绍了如何在C#参数1上修复错误cs1503:无法从'system.reflection.assembly'转换为'system.type'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  public   class  CommandHandler 
{
private DiscordSocketClient _client;

private CommandService _service;

public CommandHandler(DiscordSocketClient客户端)
{
_client = client;

_service = new CommandService();

_service.AddModuleAsync(Assembly.GetEntryAssembly());

_client.MessageReceived + = HandleCommandAsync;
}

private async 任务HandleCommandAsync(SocketMessage s)
{
var msg = s as SocketUserMessage;
if (msg == null return ;

var context = new SocketCommandContext(_client,msg);

int argPos = 0 ;
if (msg.HasCharPrefix(' !) ' ref argPos))
{
var result = await _service.ExecuteAsync(context,argPos);

if (!result.IsSuccess&& result.Error!= CommandError.UnknownCommand)
{
await context.Channel.SendMessageAsync(result.ErrorReason);
}
}
}
}





我尝试了什么:



没什么我对C#

解决方案

的了解不多通过查看你的CommandService类,特别是AddModuleAsync方法。



很可能它需要一个Type,而你正在通过一个程序集。



我们不能为你做那件事;我们无法访问您的其他代码!


AddModulesAsync



使用s:模块

public class CommandHandler
    {
        private DiscordSocketClient _client;

        private CommandService _service;

        public CommandHandler(DiscordSocketClient client)
        {
            _client = client;

            _service = new CommandService();

            _service.AddModuleAsync(Assembly.GetEntryAssembly());

            _client.MessageReceived += HandleCommandAsync;
        }

        private async Task HandleCommandAsync(SocketMessage s)
        {
            var msg = s as SocketUserMessage;
            if (msg == null) return;

            var context = new SocketCommandContext(_client, msg);

            int argPos = 0;
            if (msg.HasCharPrefix('!', ref argPos))
            {
              var result = await _service.ExecuteAsync(context, argPos);

                if (!result.IsSuccess && result.Error != CommandError.UnknownCommand)
                {
                    await context.Channel.SendMessageAsync(result.ErrorReason);
                }
            }
        }
    }



What I have tried:

Nothing much I don't know that much about C#

解决方案

Start by looking at your CommandService class, and specifically at the AddModuleAsync method.

The chances are that it expects a Type, and you are passing an Assembly.

We can't do that for you; we don't have any access to your other code!


AddModulesAsync

With an "s": Modules


这篇关于如何在C#参数1上修复错误cs1503:无法从'system.reflection.assembly'转换为'system.type'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆