2
为Discord编写机器人程序,并希望在发生错误时更易于调试。需要帮助才能转换为多类分层结构
我想借此
private static void Main(string[]) args)
{
var client = new DiscordClient();
client.Connect(" ");
var commands = new client.Services.Get<CommandService>();
commands.CreateCommand("test")
.Description("This is a test command.")
.Do(async e =>
{
await e.Channel.SendMessage("Test Successful!");
});
}
和,如果可能的话,做起来很每条命令都有自己的类文件,它是这样的
namespace Console.scripts
{
class test
{
commands.CreateCommand("test")
.Description("This is a test command.)
.Do(async e =>
{
await e.Channel.SendMessage("Test Successful!");
});
}
}
我从来没有很好的与多路复用器,即使是类似的例子也会有所帮助。
从注册它我的理解,目前我会使用CommandEventArgs事件,但我遇到了问题上线“.Do(command.Run);” “这个异步方法缺少'等待'操作符并且将同步运行” “只能将赋值,调用,增量,减量和新对象表达式用作语句”。注意将该行编辑为“.Do(async e => command.Run);” – TehPirate
然后在命令类(在这种情况下为'TestCommand')将'async'添加到'Run'方法签名。然后切换到'.Do(async e => await command.Run(e));'。 – BrunoLM
当在SDK外部应用异步时,会出现一个未知方法。 – TehPirate