本文整理汇总了C#中Discord.DiscordClient.AddModule方法的典型用法代码示例。如果您正苦于以下问题:C# DiscordClient.AddModule方法的具体用法?C# DiscordClient.AddModule怎么用?C# DiscordClient.AddModule使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Discord.DiscordClient
的用法示例。
在下文中一共展示了DiscordClient.AddModule方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
public void Start()
{
const string configFile = "configuration.json";
try
{
_config = Configuration.LoadFile(configFile); // Load the configuration from a saved file.
}
catch
{
_config = new Configuration(); // Create a new configuration file if it doesn't exist.
Console.WriteLine("Config file created. Enter a token.");
Console.Write("Token: ");
_config.Token = Console.ReadLine(); // Read the user's token from the console.
_config.SaveFile(configFile);
}
_client = new DiscordClient(x => // Create a new instance of DiscordClient
{
x.AppName = "Moetron";
x.AppUrl = "https://github.com/Cappucirno/moetron";
x.AppVersion = "1.0";
x.LogLevel = LogSeverity.Info; // Mirror relevant information to the console.
})
.UsingCommands(x => // Configure the Commands extension
{
x.PrefixChar = _config.Prefix; // Set the prefix from the configuration file
x.HelpMode = HelpMode.Private; // Enable the automatic `!help` command.
})
.UsingPermissionLevels((u, c) => (int)GetPermission(u, c)) // Permission levels are used to check basic or custom permissions
.UsingModules(); // Configure the Modules extension
// With LogLevel enabled, mirror info to the console in this format.
_client.Log.Message += (s, e) => Console.WriteLine($"[{e.Severity}] {e.Source}: {e.Message}");
// Load modules into the Modules extension.
_client.AddModule<AdminModule>("Admin", ModuleFilter.None);
_client.AddModule<EventModule>("Events", ModuleFilter.None);
_client.AddModule<PointModule>("Points", ModuleFilter.None);
_client.AddModule<ImageModule>("Images", ModuleFilter.None);
_client.AddModule<UtilModule>("Utility", ModuleFilter.None);
// Proper Login.md
_client.ExecuteAndWait(async () =>
{
while (true)
{
try
{
await _client.Connect(_config.Token, TokenType.Bot);
break;
}
catch (Exception ex)
{
_client.Log.Error("Login Failed", ex);
await Task.Delay(_client.Config.FailedReconnectDelay);
}
}
});
//_client.SetGame("with your :heart:");
}
示例2: Start
private void Start(string[] args)
{
#if !DNXCORE50
Console.Title = $"{AppName} (Discord.Net v{DiscordConfig.LibVersion})";
#endif
GlobalSettings.Load();
_client = new DiscordClient(x =>
{
x.AppName = AppName;
x.AppUrl = AppUrl;
x.MessageCacheSize = 0;
x.UsePermissionsCache = true;
x.EnablePreUpdateEvents = true;
x.LogLevel = LogSeverity.Debug;
x.LogHandler = OnLogMessage;
})
.UsingCommands(x =>
{
x.AllowMentionPrefix = true;
x.HelpMode = HelpMode.Public;
x.ExecuteHandler = OnCommandExecuted;
x.ErrorHandler = OnCommandError;
})
.UsingModules()
.UsingAudio(x =>
{
x.Mode = AudioMode.Outgoing;
x.EnableMultiserver = true;
x.EnableEncryption = true;
x.Bitrate = AudioServiceConfig.MaxBitrate;
x.BufferLength = 10000;
})
.UsingPermissionLevels(PermissionResolver);
_client.AddService<SettingsService>();
_client.AddService<HttpService>();
_client.AddModule<AdminModule>("Admin", ModuleFilter.ServerWhitelist);
_client.AddModule<ColorsModule>("Colors", ModuleFilter.ServerWhitelist);
_client.AddModule<FeedModule>("Feeds", ModuleFilter.ServerWhitelist);
_client.AddModule<GithubModule>("Repos", ModuleFilter.ServerWhitelist);
_client.AddModule<ModulesModule>("Modules", ModuleFilter.None);
_client.AddModule<PublicModule>("Public", ModuleFilter.None);
_client.AddModule<TwitchModule>("Twitch", ModuleFilter.ServerWhitelist);
_client.AddModule<StatusModule>("Status", ModuleFilter.ServerWhitelist);
//_client.AddModule(new ExecuteModule(env, exporter), "Execute", ModuleFilter.ServerWhitelist);
#if PRIVATE
PrivateModules.Install(_client);
#endif
//Convert this method to an async function and connect to the server
//DiscordClient will automatically reconnect once we've established a connection, until then we loop on our end
//Note: ExecuteAndWait is only needed for Console projects as Main can't be declared as async. UI/Web applications should *not* use this function.
_client.ExecuteAndWait(async () =>
{
while (true)
{
try
{
await _client.Connect(GlobalSettings.Discord.Email, GlobalSettings.Discord.Password);
_client.SetGame("Discord.Net");
//await _client.ClientAPI.Send(new Discord.API.Client.Rest.HealthRequest());
break;
}
catch (Exception ex)
{
_client.Log.Error($"Login Failed", ex);
await Task.Delay(_client.Config.FailedReconnectDelay);
}
}
});
}