【发布时间】:2017-02-25 06:42:25
【问题描述】:
我正在学习制作不和谐机器人的教程,在学习了设置机器人的基础知识后,我一直遇到这个异常:
System.Reflection.TargetInvocationException 已被抛出。调用的目标已抛出异常。
这是我的代码:
using Discord.Commands;
using Discord;
using System;
namespace TestBot
{
public class MyBot
{
DiscordClient discord;
public MyBot()
{
discord = new DiscordClient(x =>
{
x.LogLevel = LogSeverity.Info;
x.LogHandler = Log;
});
discord.UsingCommands(x =>
{
x.PrefixChar = '!';
x.AllowMentionPrefix = true;
});
var commands = discord.GetService<CommandService>();
commands.CreateCommand("test")
.Do(async (e) =>
{
await e.Channel.SendMessage("response");
});
discord.ExecuteAndWait(async () =>
{
await discord.Connect("BOT_TOKEN", TokenType.Bot);
});
}
private void Log(object sender, LogMessageEventArgs e)
{
Console.WriteLine(e.Message);
}
}
}
MonoDevelop 说这段代码发生了异常:
discord.ExecuteAndWait(async () =>
{
await discord.Connect("BOT_TOKEN", TokenType.Bot);
});
我不知道如何解决这个问题,所以任何帮助将不胜感激。
(由于这是我在这里的第一篇文章,任何关于如何改进我的帖子的建议也非常感谢。)
【问题讨论】:
-
应该有内部异常,看看吧
-
@Gusman 我应该寻找什么?
-
内部异常会有真正的异常