Discord 机器人无法启动,type/namespace 名称
Discord bot won't start, type/namespace name
基本上,我为我的第一个 discord 机器人编写了代码(可能是错误的)。基本的,只是登录,不会 运行。它给我关于
的错误
The type or namespace name 'DiscordClient could or could not be found
与 'LogMessageEventArgs'
相同
程序代码:
using Discord;
using Discord.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DiscordBot
{
class Program
{
static void Main(string[] args)
{
MyBot bot = MyBot();
}
}
}
MyBot 代码:
using Discord;
using Discord.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DiscordBot
{
class MyBot
{
DiscordClient discord;
public MyBot()
{
discord = new DiscordClient(x =>
{
x.LogLevel = LogSeverity.Info;
x.LogHandler = Log;
});
discord.ExecuteAndWait(async () =>
{
await discord.Connect("the token");
});
}
private void Log (object sender, LogMessageEventArgs e)
{
Console.WriteLine(e.Message);
}
}
}
DiscordClient
类型在 "Discord.Net" 包中不存在,因此您必须自己创建它或(通常)使用 NuGet 包附带的预定义类型之一。请参阅 this 获取良好的入门指南。
基本上,我为我的第一个 discord 机器人编写了代码(可能是错误的)。基本的,只是登录,不会 运行。它给我关于
的错误The type or namespace name 'DiscordClient could or could not be found
与 'LogMessageEventArgs'
相同程序代码:
using Discord;
using Discord.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DiscordBot
{
class Program
{
static void Main(string[] args)
{
MyBot bot = MyBot();
}
}
}
MyBot 代码:
using Discord;
using Discord.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DiscordBot
{
class MyBot
{
DiscordClient discord;
public MyBot()
{
discord = new DiscordClient(x =>
{
x.LogLevel = LogSeverity.Info;
x.LogHandler = Log;
});
discord.ExecuteAndWait(async () =>
{
await discord.Connect("the token");
});
}
private void Log (object sender, LogMessageEventArgs e)
{
Console.WriteLine(e.Message);
}
}
}
DiscordClient
类型在 "Discord.Net" 包中不存在,因此您必须自己创建它或(通常)使用 NuGet 包附带的预定义类型之一。请参阅 this 获取良好的入门指南。