在 Visual Studio 2019 中探索 Discord.net 时,我遇到了错误:
错误 CS0411 方法“DiscordHostBuilderExtensions.ConfigureDiscordHost(IHostBuilder, Action<HostBuilderContext, DiscordHostConfiguration>?)”的类型参数无法根据使用情况确定。尝试显式定义类型参数。ConsoleApp2(第 34 行)
using Discord;
using Discord.Addons.Hosting;
using Discord.Commands;
using Discord.Interactions;
using Microsoft.Extensions.Primitives;
using Discord.WebSocket;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System.IO;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class Program
{
static async Task Main()
{
var builder = new HostBuilder()
.ConfigureAppConfiguration(x =>
{
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("config.json", false, true)
.Build();
x.AddConfiguration(config);
})
.ConfigureLogging(x =>
{
x.AddConsole();
x.SetMinimumLevel(LogLevel.Debug);
})
.ConfigureDiscordHost((context, config) =>
{
config.SocketConfig = new DiscordSocketConfig
{
LogLevel = LogSeverity.Debug,
AlwaysDownloadUsers = false,
MessageCacheSize = 200
};
config.Token = context.Configuration["token"];
})
.UseCommandService((context, config) =>
{
config.CaseSensitiveCommands = false;
config.LogLevel = LogSeverity.Debug;
config.DefaultRunMode = Discord.Commands.RunMode.Async;
})
.ConfigureServices((context, services) =>
{
})
.UseConsoleLifetime();
var host = builder.Build();
using (host)
{
await host.RunAsync();
}
}
}
}
使用此方法的描述中所需的内容 - 指定客户端类型
或者是时候切换到更新的不和谐库(4 个甚至 5 个)